本文实例分析了PHP计算日期相差天数的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<?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 . "天" ;
?>
|
1
2
3
4
5
6
|
//---------------------------------------------
$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;
|
统计几天以后到期的数据
1
|
datediff(yxdate_star,now())
|
返回 天数 : yxdate_star-now()
希望本文所述对大家PHP程序设计有所帮助。