-2

I have two dates of the form:

Start Date: 2015-01-25 13:45:01 
End Date: 2015-01-28 02:58:01

Now I need to find the day between these two in the following form:

2015-01-25
2015-01-26
2015-01-27
2015-01-28

How can I do this in PHP?

Rizier123
  • 58,877
  • 16
  • 101
  • 156
riccardo airone
  • 506
  • 1
  • 6
  • 21

1 Answers1

0

This should work for you:

(Here i just simply used 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 />";

?>

Output:

2015-01-25
2015-01-26
2015-01-27
2015-01-28
Rizier123
  • 58,877
  • 16
  • 101
  • 156