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