任何人都可以给我一个解决方案,找不到给定日期之间的日期而不使用php的DATEINTERVAL
函数吗?
我到目前为止已尝试过:
$event_start_on='2013-09-01 01:06:00';
$event_expire_on='2013-10-01 01:06:00';
$getdates=array();
$d=0;
if($rs->report_cycle=="Weekly"){
$takeinterval=new DateInterval('P7D');
}
else if($rs->report_cycle=="Biweekly"){
$takeinterval=new DateInterval('P15D');
}
else if($rs->report_cycle=="Monthly")
{
$takeinterval=new DateInterval('P30D');
}
else{
$takeinterval=new DateInterval('P1D');
}
$period=new DatePeriod($event_start_on,$takeinterval,$event_expire_on);
foreach($period as $dt){
$getdates[$d]=$dt->format("Y-m-d H:i:s");
$d++;
}
答案 0 :(得分:0)
这是一个不使用DateInterval
switch ($rs->report_cycle){
case "Weekly":
$period = '+1 week'; break;
case "Biweekly":
$period = '+15 days'; break;
case "Monthly":
$period = '+1 month'; break;
default:
$period = '+1 day';
}
$start = new DateTime('2013-09-01');
$end = new DateTime('2013-10-01');
while ($start < = $end)
{
echo $start->format("m/d/Y") . PHP_EOL;
$start->modify($period);
}