3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $startDate = new DateTime('@' . mktime(0, 0, 0, date("m"), date("d") - 7, date("Y"))); $optionalStartDate = '2018-01-01 00:00:00'; $dt = new DateTime($optionalStartDate); print_r($startDate->format('Y-m-d H:i:s')); print_r($dt);
based on 77o9n
Output for 5.6.38 - 7.3.0rc3
2018-10-22 22:00:00DateTime Object ( [date] => 2018-01-01 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam )