Example Analysis of calculating the number of days for date difference in PHP and instance analysis of the number of days
This article describes how to calculate the number of days for date difference in PHP. We will share this with you for your reference. The details are as follows:
<? PHP // How many days are there today different from January 1, October 27, 2016 $ 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 "today is different from October 27, 2016 ". $ Days. "Day"; echo "<br>"; // The number of days from today to January 1, September 9, 2018 $ 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 "today to march September 9, 2018, there will be ". $ Days. "Day";?>
// Combine $ 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 expired data in a few days
Datediff (yxdate_star, now ())
Returned days: yxdate_star-now ()