In PHP, how many days are there before my birthday?

Source: Internet
Author: User
Tags time zones
For example, if the birthday is 10-4, there should be more than 200 days left for his birthday. For example, if the birthday is 10-04, there should be more than 200 days left for his birthday.

Reply content:

For example, if the birthday is 10-04, there should be more than 200 days before his birthday.

Http://php.net/manual/en/datetime.diff.php


  diff($datetime2);echo $interval->format('%R%a days');

When calculating a date, you are very reluctant to calculate it by yourself, because this is a complicated problem. A day is not always 24 hours (for example, the day that switches from a non-renewal to a failover is only 23 hours ), every hour is not 3600 seconds (a leap second is added when the Difference Between UTC and GMT is more than one second), and a year is not always 365 days (a leap year ), A leap year is not once every four years (the first year of every century must be divided by 400 million RMB ). There are also differences between different time zones. The time zones are not just as simple as a few hours of time difference.

Therefore, you must use a professional library to calculate the time. Of course, the DateTime provided by PHP may not cover all the situations, but it is self-contained and can be used in most cases.

Here is a very good php time component: https://github.com/briannesbitt/Carbon

ceil( ( strtotime ("2015-10-04") - strtotime( date("y-m-d") ) )/86400 );

@ Wang ziting diff I have never used it before.

Carbon + 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.