i am trying to get the year month from 2018-01-06 to till day using the php datetime object using the code
function getMonths(){
$st_date = new DateTime('2019-01-01');
$yms = array($st_date);
while($st_date < new DateTime()){
array_push($yms, $st_date->add(new DateInterval('P1M')));
}
print_r($yms);
}
But the ouput is showing the same values on all the items in the array $yms
Array
(
[0] => DateTime Object
(
[date] => 2019-03-01 00:00:00
[timezone_type] => 3
[timezone] => Asia/Kolkata
)
[1] => DateTime Object
(
[date] => 2019-03-01 00:00:00
[timezone_type] => 3
[timezone] => Asia/Kolkata
)
....
)