<?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('first day of last year');
$end = strtotime('last day of last year');
break;
default:
$start = strtotime('now');
$end = strtotime('now');
}
return array($start, $end);
}
var_dump(period_to_timestamps('last_7_days'));