Home  >  Article  >  Backend Development  >  PHP calculation of days difference between dates example analysis_php skills

PHP calculation of days difference between dates example analysis_php skills

WBOY
WBOYOriginal
2016-05-16 19:58:072003browse

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

//---------------------------------------------
$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;

Stats data that will expire in a few days

datediff(yxdate_star,now())

Return the number of days: yxdate_star-now()

Readers who are interested in more PHP-related content can check out the special topics of this site: "PHP Object-Oriented Programming Introductory Tutorial", "Summary of PHP String Usage ", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone in PHP programming.

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