-2

Can any one give me a solution for finding dates between given dates without using DATEINTERVAL function of php?

i have tried so far:

$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++;
                        }
anumavu
  • 13
  • 3

1 Answers1

0

Here is a solution that doesn't use 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);
}
John Conde
  • 217,595
  • 99
  • 455
  • 496