In this paper, we analyze how to calculate the date difference between days in PHP. Share to everyone for your reference, specific as follows:
? PHP
//Today and October 27, 2016 difference between the number of days
$Date _1=date ("y-m-d");
$Date _2= "2016-10-27";
$d 1=strtotime ($Date _1);
$d 2=strtotime ($Date _2);
$Days =round (($d 1-$d 2)/3600/24);
Echo "Today differs from October 27, 2016". $Days. " Days ";
echo "<br>";
How many days are there
$Date _1=date ("y-m-d") today to September 9, 2018;
$Date _2= "2018-09-09";
$d 1=strtotime ($Date _1);
$d 2=strtotime ($Date _2);
$Days =round (($d 2-$d 1)/3600/24);
Echo "Today to September 9, 2018 there is also". $Days. " 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 data that expires after a few days
DateDiff (Yxdate_star,now ())
Return days: Yxdate_star-now ()
For more information about PHP interested readers can view the site topics: "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP Common database Operation tips Summary"
I hope this article will help you with the PHP program design.