0

How do I retrieve all the months on 2015-October to 2016-May date range with PHP? ex - 2015-November, 2015-December, 2016-January.. so on

Pupil
  • 23,834
  • 6
  • 44
  • 66
GRTZ
  • 330
  • 6
  • 17

1 Answers1

0

There is greate example in the PHP docs. http://php.net/manual/en/class.dateperiod.php

<?php

$begin = new DateTime( '2012-08-01' );
$end = new DateTime( '2012-08-31' );
$end = $end->modify( '+1 day' ); 

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

foreach($daterange as $date){
    echo $date->format("Ymd") . "<br>";
}
?>

Just provide the needed date format and you are done.

Change it here:

$date->format("Ymd")

As @Uchiha said there is an answer here: https://stackoverflow.com/a/18743012/2160958

Community
  • 1
  • 1
vardius
  • 6,326
  • 8
  • 52
  • 97