反正有没有在PHP中找到日期差异?我有从2003年10月17日至2004年3月24日的输入。我需要结果在这两天内有多少天。如果说224天,我只需要输出天数。在php中查找日期差异?
我通过mysql找到解决方案,但我需要在PHP中。任何人都可以帮助我,请提前致谢。
反正有没有在PHP中找到日期差异?我有从2003年10月17日至2004年3月24日的输入。我需要结果在这两天内有多少天。如果说224天,我只需要输出天数。在php中查找日期差异?
我通过mysql找到解决方案,但我需要在PHP中。任何人都可以帮助我,请提前致谢。
可以使用解析时间戳功能日期转换为时间戳,减去时间戳,然后转换结果时间戳(秒)天:
floor((strtotime("2004-03-24") - strtotime("2003-10-17"))/86400);
$start = new DateTime('2003-10-17');
$end = new DateTime('2004-03-24');
$diff = $start->diff($end);
echo $diff->format('%d days');
...应该这样做。
仅供参考请参阅DateTime和DateInterval。
但是请注意,只有在PHP 5.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);
一个细节博客是在这里:http://goo.gl/YOsfPX
感谢好的回答这个 – Karthik 2010-04-21 04:30:48