Home >Backend Development >PHP Tutorial >PHP计算日期相差天数实例分析_PHP

PHP计算日期相差天数实例分析_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-27 10:37:16918browse

本文实例分析了PHP计算日期相差天数的方法。分享给大家供大家参考,具体如下:

<&#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;

统计几天以后到期的数据

datediff(yxdate_star,now())

返回 天数 : yxdate_star-now()

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

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