PHP Gets the date range for the current week (month)
The program needs to write a date range that gets the current week, which is the date range from Monday to Sunday.
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;
}
Author:zhxia 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 two functions above Author:zhxia
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://on 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;
}
http://www.bkjia.com/PHPjc/847199.html www.bkjia.com true http://www.bkjia.com/PHPjc/847199.html techarticle PHP Gets the date range of the current week (month) The program needs to write a date range that gets the current week, that is, the date range from Monday to Sunday. function Getweekrang ...