3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $format = 'Y-m-d H:i:s'; $days_left = 7; $date = time(); echo DateTime::createFromFormat('Y-m-d', '12 days ago')->format('Y-m-d'); $dateParts = explode('-', date('Y-m-d', $date)); var_dump(DateInterval::createFromDateString("12 days ago")); $start = mktime(0,0,0, $dateParts[1], intval($dateParts[2])-$days_left, $dateParts[0]); echo date($format,$start)."\n"; $end = mktime(0,0,0, $dateParts[1], intval($dateParts[2])-($days_left-1), $dateParts[0]); echo date($format,$end);
based on IHuPC
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to a member function format() on boolean in /in/5CsF2:5 Stack trace: #0 {main} thrown in /in/5CsF2 on line 5
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Fatal error: Call to a member function format() on boolean in /in/5CsF2 on line 5
Process exited with code 255.
Output for 5.5.0 - 5.5.37
Fatal error: Call to a member function format() on a non-object in /in/5CsF2 on line 5
Process exited with code 255.