3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $nbMonth = 3; $now = new \DateTime('2017-01-01 11:55:00'); $datePeriodStart = $now->sub(new \DateInterval('P'.$nbMonth.'M')); echo $datePeriodStart->format('Y-m-d H:i:s') . "\n"; $datePeriodStart->setDate($datePeriodStart->format('Y'), $datePeriodStart->format('n'), 1); $datePeriodStart->setTime(0,0); echo $datePeriodStart->format('Y-m-d H:i:s') . "\n"; $endDate = new DateTime('last day of previous month'); echo $endDate->format('Y-m-d H:i:s') . "\n";
based on RmFsd
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0beta1
2016-10-01 11:55:00 2016-10-01 00:00:00 2017-05-31 12:00:53