Home >Backend Development >PHP Tutorial >PHP example code for calculating the number of days between two dates

PHP example code for calculating the number of days between two dates

怪我咯
怪我咯Original
2017-07-10 09:37:263732browse

This article mainly introduces the method of calculating the number of days between dates in PHP, and analyzes the related skills of PHP date and time operation and conversion in the form of examples. Friends in need can refer to the following

This article analyzes the method of calculating the number of days between dates in PHP. Share it with everyone for your reference, the details are as follows:

<?PHP
//今天与2016年10月27日相差多少天
$Date_1=date("Y-m-d");
$Date_2="2016-10-27";
$d1=strtotime($Date_1);
$d2=strtotime($Date_2);
$Days=round(($d1-$d2)/3600/24);
echo  "今天与2016年10月27日相差".$Days."天";
echo "<br>";
//今天到2018年9月9日还有多少天
$Date_1=date("Y-m-d");
$Date_2="2018-09-09";
$d1=strtotime($Date_1);
$d2=strtotime($Date_2);
$Days=round(($d2-$d1)/3600/24);
echo  "今天到2018年9月9日还有".$Days."天";
?>
//---------------------------------------------
$arrayStartDate =explode("/",$myStartDate); 
$arrayEndDate = explode("/",$myEndDate);
$jdStartDate = cal_to_jd(CAL_GREGORIAN,$arrayStartDate[1],$arrayStartDate[0],$arrayStartDate[2]);
$jdEndDate = cal_to_jd(CAL_GREGORIAN,$arrayEndDate[1],$arrayEndDate[0],$arrayEndDate[2]);
$duration = $jdEndDate - $jdStartDate + 1;

Count the data that will expire in a few days

datediff(yxdate_star,now())

Return the number of days: yxdate_star-now()

The above is the detailed content of PHP example code for calculating the number of days between two 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