Home >Backend Development >PHP Tutorial >Example analysis of calculating the number of days difference between dates using PHP

Example analysis of calculating the number of days difference between dates using PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 09:02:071151browse

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:

<&#63;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;

Statistics of data that will expire in a few days

datediff(yxdate_star,now())

Return number of days: yxdate_star-now()

More interested in PHP related content Readers can check out the special topics on this site: "Introduction Tutorial on PHP Object-Oriented Programming", "Summary of PHP String Usage", "Introduction Tutorial on PHP+MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

Hope this article The above will be helpful to everyone in PHP programming.

The above introduces the analysis of PHP calculation of days difference between dates, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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 sends POST requestNext article:PHP sends POST request