Home >Backend Development >PHP Problem >How to calculate the difference between dates in php
php method to calculate the number of days difference between dates: first create a PHP sample file; then define two times and dates; then calculate through the "round(($d2-$d1)/3600/24);" method The difference between the two dates is only a few days.
Recommended: "PHP Video Tutorial"
php calculates the number of days between dates
<?PHP //今天与2004年10月27日相差多少天 $Date_1=date("Y-m-d"); $Date_2="2004-10-27"; $d1=strtotime($Date_1); $d2=strtotime($Date_2); $Days=round(($d1-$d2)/3600/24); Echo "今天与2004年10月27日相差".$Days."天"; Echo "<br>"; //今天到2008年9月9日还有多少天 $Date_1=date("Y-m-d"); $Date_2="2008-09-09"; $d1=strtotime($Date_1); $d2=strtotime($Date_2); $Days=round(($d2-$d1)/3600/24); Echo "今天到2008年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()
The above is the detailed content of How to calculate the difference between dates in php. For more information, please follow other related articles on the PHP Chinese website!