This article summarizes three php functions for getting calendars, php is used to obtain the calendar of the month of the specified date, the start date and end date of the month of the specified date, and the date range of the current week.
This article summarizes three php functions for getting calendars, php is used to obtain the calendar of the month of the specified date, the start date and end date of the month of the specified date, and the date range of the current week.
Provides a date to obtain the calendar list of the week corresponding to this date. The key is the week Id.
$ Month_date = '2017-09-25 '; $ start_time = strtotime ($ month_date); $ start_week = date ('w', $ start_time); $ total_month_day = date ('T ', $ start_time); $ weeks_in_month = ceil ($ start_week + $ total_month_day)/7); $ month_day_arr = []; $ start_month_day = 1; for ($ I = 0; $ I <$ weeks_in_month; $ I ++) {for ($ j = 0; $ j <7; $ j ++) {if ($ I = 0 & $ j >=$ start_week) {$ month_day_arr [$ I] [$ j] = $ start_month_day; $ start_month_day ++ ;} elseif ($ I = 0) {$ month_day_arr [$ I] [$ j] = '';} else {$ month_day_arr [$ I] [$ j] = $ start_month_day; $ start_month_day ++;} if ($ start_month_day> $ total_month_day) {break ;}} echo"
"; Print_r ($ month_day_arr ); array ([0] => Array ([0] => [1] => [2] => 1 [3] => 2 [4] => 3 [5] => 4 [6] => 5) [1] => Array ([0] => 6 [1] => 7 [2] => 8 [3] => 9 [4] => 10 [5] => 11 [6] => 12) [2] => Array ([0] => 13 [1] => 14 [2] => 15 [3] => 16 [4] => 17 [5] => 18 [6] => 19) [3] => Array ([0] => 20 [1] => 21 [2] => 22 [3] => 23 [4] => 24 [5] => 25 [6] => 26) [4] => Array ([0] => 27 [1] => 28 [2] => 29 [3] => 30 ))Obtains the start and end dates of the month of the specified date.
/*** @ Param string $ date * @ param boolean: return the start date. Otherwise, return the end date * @ return array * @ access private */private function getMonthRange ($ date, $ returnFirstDay = true) {$ timestamp = strtotime ($ date); if ($ returnFirstDay) {$ monthFirstDay = date ('Y-S-1 00:00:00 ', $ timestamp ); return $ monthFirstDay;} else {$ mdays = date ('T', $ timestamp); $ monthLastDay = date ('Y-m -'. $ mdays. '23:59:59 ', $ timestamp); return $ monthLastDay ;}}
Obtain the date range of 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-S-1 00:00:00 ', $ timestamp ); $ ret ['date'] = 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 ;}
,