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

怪我咯
Release: 2023-03-13 09:56:01
Original
3628 people have browsed it

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."天";
?>
Copy after login
//---------------------------------------------
$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;
Copy after login

Count the data that will expire in a few days

datediff(yxdate_star,now())
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!