How to calculate the number of days between dates using PHP? This article mainly introduces how PHP uses strtotime to calculate the number of days between two dates, and analyzes the skills of PHP in manipulating date and time. I hope to be helpful.
The example in this article describes how PHP uses strtotime to calculate the number of days between two given dates. Share it with everyone for your reference. The specific analysis is as follows:
PHP’s strtotime function is used to parse the date and time description of any English text into a Unix timestamp. This function will use the TZ environment variable (if available) to calculate the timestamp. It returns a timestamp if the execution is successful, otherwise it returns FALSE. Prior to PHP 5.1.0, this function would return -1.
$date1 = date('Y-m-d'); $date2 = '2005-03-01′; $days = (strtotime() – strtotime()) / (60 * 60 * 24); echo "Number of days since '2005-03-01′: $days";
Related recommendations:
##PHP time formatting parameters
php Detailed explanation of timestamp (UNIX) usage
The above is the detailed content of PHP calculates the number of days between dates. For more information, please follow other related articles on the PHP Chinese website!