PHP calculates the number of days between dates

*文
Release: 2023-03-18 12:50:01
Original
4239 people have browsed it

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";
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template