3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function period_to_timestamps($period) { switch($period) { case "last_7_days": $start = strtotime('-7 days'); $end = strtotime('now'); break; case "this_month": $start = strtotime('first day of this month'); $end = strtotime('now'); break; case "last_month": $start = strtotime('first day of last month'); $end = strtotime('last day of last month'); break; case "this_year": $start = strtotime('01-01-' . date('Y', strtotime('now'))); $end = strtotime('now'); break; case "last_year": $start = strtotime('01-01-' . date('Y', strtotime('now -1 year'))); $end = strtotime('12-31-' . date('Y', strtotime('now -1 year'))); break; default: $start = strtotime('now'); $end = strtotime('now'); } return array(date('m-d-Y', $start), date('m-d-Y', $end)); } var_dump(period_to_timestamps('last_7_days')); var_dump(period_to_timestamps('this_month')); var_dump(period_to_timestamps('last_month')); var_dump(period_to_timestamps('this_year')); var_dump(period_to_timestamps('last_year'));
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(2) { [0]=> string(10) "06-17-2014" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "06-01-2014" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "05-01-2014" [1]=> string(10) "05-31-2014" } array(2) { [0]=> string(10) "01-01-2014" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "01-01-2013" [1]=> string(10) "01-01-1970" }
Output for 5.1.3 - 5.2.17
array(2) { [0]=> string(10) "06-17-2014" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "01-01-1970" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "01-01-1970" [1]=> string(10) "01-01-1970" } array(2) { [0]=> string(10) "01-01-2014" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "01-01-2013" [1]=> string(10) "01-01-1970" }
Output for 5.1.0 - 5.1.2
array(2) { [0]=> string(10) "06-17-2014" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "01-01-1970" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "01-01-1970" [1]=> string(10) "01-01-1970" } array(2) { [0]=> string(10) "01-01-1970" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "01-01-1970" [1]=> string(10) "01-01-1970" }
Output for 4.3.0 - 5.0.5
array(2) { [0]=> string(10) "06-17-2014" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "01-01-1970" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "01-01-1970" [1]=> string(10) "01-01-1970" } array(2) { [0]=> string(10) "07-07-2006" [1]=> string(10) "06-24-2014" } array(2) { [0]=> string(10) "07-06-2006" [1]=> string(10) "01-03-2020" }