Nonsense not much, on the code
Copy Code code as follows:
Gets the start and end times of the week on which the specified date is located
function Getweekrange ($date) {
$ret =array ();
$timestamp =strtotime ($date);
$w =strftime ('%u ', $timestamp);
$ret [' Sdate ']=date (' y-m-d 00:00:00 ', $timestamp-($w-1) *86400);
$ret [' Edate ']=date (' y-m-d 23:59:59 ', $timestamp + (7-$w) *86400);
return $ret;
}
Gets the start date and end date of the month on which the specified date is located
function Getmonthrange ($date) {
$ret =array ();
$timestamp =strtotime ($date);
$mdays =date (' t ', $timestamp);
$ret [' Sdate ']=date (' y-m-1 00:00:00 ', $timestamp);
$ret [' Edate ']=date (' y-m-'. $mdays. 23:59:59 ', $timestamp);
return $ret;
}
Application of the above two functions
function GetFilter ($n) {
$ret =array ();
Switch ($n) {
Case 1://Yesterday
$ret [' Sdate ']=date (' y-m-d 00:00:00 ', Strtotime ('-1 day '));
$ret [' Edate ']=date (' y-m-d 23:59:59 ', Strtotime ('-1 day '));
Break
Case 2://this week
$ret =getweekrange (Date (' y-m-d '));
Break
Case 3://one weeks.
$strDate =date (' y-m-d ', Strtotime ('-1 week '));
$ret =getweekrange ($strDate);
Break
Case 4://Last week
$strDate =date (' y-m-d ', Strtotime ('-2 week '));
$ret =getweekrange ($strDate);
Break
Case 5://this month
$ret =getmonthrange (Date (' y-m-d '));
Break
Case 6://last month
$strDate =date (' y-m-d ', Strtotime ('-1 month '));
$ret =getmonthrange ($strDate);
Break
}
return $ret;
}