PHP obtains the date range of the current week (month. PHP needs to get the date range of the current week (month), and write a date range to get the current week, that is, from Monday to Sunday. FunctiongetWeekRang PHP gets the date range of the current week (month)
The program needs to write a date range for obtaining the current week, that 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 ['update'] = date ('Y-m-d 23:59:59 ', $ timestamp + (7-$ w) * 86400 );
Return $ ret;
}
// Author: zhxia obtains the start date and end date of the month of the specified date.
Function getMonthRange ($ date ){
$ Ret = array ();
$ Timestamp = strtotime ($ date );
$ Mdays = date ('t', $ timestamp );
$ Ret ['sdate'] = date ('Y-M-1 00:00:00 ', $ timestamp );
$ Ret ['update'] = date ('Y-m-'. $ mdays. '23:59:59', $ timestamp );
Return $ ret;
}
// Author: application of the preceding two functions of zhxia
Function getFilter ($ n ){
$ Ret = array ();
Switch ($ n ){
Case 1: // yesterday
$ Ret ['sdate'] = date ('Y-m-d 00:00:00 ', strtotime ('-1 DAY '));
$ Ret ['update'] = date ('Y-m-d 23:59:59 ', strtotime ('-1 DAY '));
Break;
Case 2: // this week
$ Ret = getWeekRange (date ('Y-m-D '));
Break;
Case 3: // last week
$ 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;
}
The date range program of week (month) needs to write a date range to obtain the current week, that is, the date range from Monday to Sunday. Function getWeekRang...