PHP retrieves the start date and end date of the week (month) of the current date // retrieves the start time and end time of the week of the specified date functiongetWeekRange ($ date) {$ ret = array (); $ timestamp = strtotime ($ dat PHP obtains the start date and end date of the week (month) where the current date is located.
// Obtain the start time and end time of the week of the specified date. 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: the application function getFilter ($ n) of the two functions above zhxia {$ ret = array (); switch ($ n) {case 1: // Yesterday $ ret ['sdate'] = date ('Y-m-d 00:00:00 ', strtotime ('-1 DAY'); $ ret ['Date'] = date ('Y-m-d 23:59:59', strtotime ('-1 DAY ')); break; case 2: // $ 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: // $ 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 ;}