3
$end_date = new DateTime($_GET['end_date']); 
$last_day_this_month = $end_date->format('d-m-Y'); //outputs 10-03-2015

$start_date = new DateTime($_GET['start_date']);
$loop_dates = $start_date->format('d-m-Y'); //outputs 22-04-2015

        for($i = $loop_dates; $i <= $last_day_this_month; $i++)
        {
                echo $i;echo '<br>';


        }

Using below loop increments the year and not dates

for($i = $loop_dates; $i <= $last_day_this_month; $i++)

How could I traverse/increment through start/end dates using loop so that it outputs all the dates from 10-03-2015 to 22-04-2015.

P.S: I am using PHP5.3 and so want to go with object oriented approach instead of using strtotime

Slimshadddyyy
  • 4,085
  • 5
  • 59
  • 121

2 Answers2

8

You can try below code

$begin = new DateTime('2013-02-01');
$end = new DateTime('2013-02-13');

$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);

foreach($daterange as $date){
    echo $date->format("d") . "<br>";
}
Lalit Sharma
  • 555
  • 3
  • 12
3

Try this one

<?php
$start = '2013-08-25';
$end = '2013-08-29';
$datediff = strtotime($end) - strtotime($start);
$datediff = floor($datediff/(60*60*24));
for($i = 0; $i < $datediff + 1; $i++){
    echo date("Y-m-d", strtotime($start . ' + ' . $i . 'day')) . "<br>";
}
?>
jay.jivani
  • 1,560
  • 1
  • 16
  • 33