我有两个日期:
Start Date: 2015-01-25 13:45:01
End Date: 2015-01-28 02:58:01
现在我需要以下列形式找到这两者之间的日期:
2015-01-25
2015-01-26
2015-01-27
2015-01-28
我如何在PHP中执行此操作?
答案 0 :(得分:0)
这应该适合你:
(这里我只是简单地使用了DatePeriod)
<?php
$start = new DateTime("2015-01-25 13:45:01 ");
$end = new DateTime("2015-01-28 02:58:01");
$end = $end->modify("+1 day");
$interval = new DateInterval('P1D');
$dateRange = new DatePeriod($start, $interval ,$end);
foreach($dateRange as $date)
echo $date->format("Y-m-d") . "<br />";
?>
输出:
2015-01-25
2015-01-26
2015-01-27
2015-01-28