Home >Backend Development >PHP Tutorial >PHow to calculate the number of days between two given dates using strtotime_PHP Tutorial

PHow to calculate the number of days between two given dates using strtotime_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:02:381002browse

P How to calculate the number of days between two given dates using strtotime

This article mainly introduces the method of using strtotime to calculate the number of days between two given dates in PHP. The example analyzes the skills of PHP operation time, which is of great practical value. Friends who need it can refer to it

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-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.

?

1

2

3

4

$date1 = date('Y-m-d');

$date2 = '2005-03-01′;

$days = (strtotime() – strtotime()) / (60 * 60 * 24);

echo "Number of days since '2005-03-01′: $days";

1 2

3

4

$date1 = date('Y-m-d');

$days = (strtotime() – strtotime()) / (60 * 60 * 24); echo "Number of days since '2005-03-01′: $days";
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/969966.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969966.htmlTechArticleP How to use strtotime to calculate the number of days between two given dates. This article mainly introduces PHP to use strtotime to calculate Method of number of days between two given dates, example analysis of php operation time...
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