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 (new DateTime('1 days ago now'))->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 9aUhn
Output for 7.1.0 - 7.2.0
2015-11-04object(DateInterval)#1 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(-12) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(-7) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 2015-10-29 00:00:00 2015-10-30 00:00:00
Output for 5.5.0 - 7.0.20
2015-11-04object(DateInterval)#1 (15) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(-12) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["weekday"]=> int(-7) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> bool(false) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 2015-10-29 00:00:00 2015-10-30 00:00:00