在php中查找日期差异?
在php中是否仍然可以找到日期差异?我有2003-10-17和2004-03-24的输入。我需要这两天内有多少天的结果。假设224天,我只需要在天内输出在php中查找日期差异?,php,date,datediff,Php,Date,Datediff,在php中是否仍然可以找到日期差异?我有2003-10-17和2004-03-24的输入。我需要这两天内有多少天的结果。假设224天,我只需要在天内输出 我通过mysql找到解决方案,但我需要php。任何人帮助我,提前谢谢 您可以使用解析时间戳功能将日期转换为时间戳,减去时间戳,然后将生成的时间戳秒转换为天: floor((strtotime("2004-03-24") - strtotime("2003-10-17"))/86400); 您可以使用解析时间戳功能将日期转换为时间戳,减去时间戳
我通过mysql找到解决方案,但我需要php。任何人帮助我,提前谢谢 您可以使用解析时间戳功能将日期转换为时间戳,减去时间戳,然后将生成的时间戳秒转换为天:
floor((strtotime("2004-03-24") - strtotime("2003-10-17"))/86400);
您可以使用解析时间戳功能将日期转换为时间戳,减去时间戳,然后将生成的时间戳秒转换为天:
floor((strtotime("2004-03-24") - strtotime("2003-10-17"))/86400);
…应该这样做
有关参考信息,请参阅和
不过请注意,这只在PHP5.3中可用
…应该这样做
有关参考信息,请参阅和
不过请注意,这只在PHP5.3中可用 示例如下:
$startDate = new DateTime( '2013-04-01' ); //intialize start date
$endDate = new DateTime( '2013-04-30' ); //initialize end date
$holiday = array('2013-04-11','2013-04-25'); //this is assumed list of holiday
$interval = new DateInterval('P1D'); // set the interval as 1 day
$daterange = new DatePeriod($startDate, $interval ,$endDate);
foreach($daterange as $date){
if($date->format("N") <6 AND !in_array($date->format("Y-m-d"),$holiday))
$result[] = $date->format("Y-m-d");
}
echo "<pre>";print_r($result);
这里有一个详细的博客:示例如下:
$startDate = new DateTime( '2013-04-01' ); //intialize start date
$endDate = new DateTime( '2013-04-30' ); //initialize end date
$holiday = array('2013-04-11','2013-04-25'); //this is assumed list of holiday
$interval = new DateInterval('P1D'); // set the interval as 1 day
$daterange = new DatePeriod($startDate, $interval ,$endDate);
foreach($daterange as $date){
if($date->format("N") <6 AND !in_array($date->format("Y-m-d"),$holiday))
$result[] = $date->format("Y-m-d");
}
echo "<pre>";print_r($result);
这里有一个详细的博客:我遇到了这种类型的错误:致命错误:类“DateTime”不是found@Karthik:是的,对不起。。。我应该提到它只在PHP5.3中可用。我会使用DateTime::createFromFormat'!“Y-m-d”,“2003-10-17”主要是因为我不喜欢依赖strotime的神奇功能。我总是觉得它会把月份和日期弄混,即使它似乎可以正常使用YY-mm-dd格式。我遇到了这种类型的错误:致命错误:类“DateTime”不是found@Karthik:是的,对不起。。。我应该提到它只在PHP5.3中可用。我会使用DateTime::createFromFormat'!“Y-m-d”,“2003-10-17”主要是因为我不喜欢依赖strotime的神奇功能。我总是觉得它会把月份和日期搞混,即使它似乎可以正确地使用yyyy-mm-dd格式。