Home  >  Article  >  Backend Development  >  PHP calculates the number of days between dates

PHP calculates the number of days between dates

*文
*文Original
2017-12-25 17:44:254170browse

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

PHP time operation

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php compresses stringsNext article:php compresses strings