PHP obtains the example of the first day and the last day of the month of the specified date. PHP obtains the first day of the month and the last day of the specified date. example code: get the first day of the month and the last day of the specified date functionGetTheMonth ($ date) PHP obtains the first day and last day of the month of the specified date.
Sample code
The code is as follows: |
|
// Obtain the first and last days of the month of the specified date Function GetTheMonth ($ date ){ $ Firstday = date ("Y-m-01", strtotime ($ date )); $ Lastday = date ("Y-m-d", strtotime ("$ firstday + 1 month-1 day ")); Return array ($ firstday, $ lastday ); } |
Sample code
// PHP obtains the first and last days of the week of the specified date.
The code is as follows: |
|
Function getdays ($ day ){ $ Lastday = date ('Y-m-D', strtotime ("$ day Sunday ")); $ Firstday = date ('Y-m-D', strtotime ("$ lastday-6 days ")); Return array ($ firstday, $ lastday ); } Print_r (getdays ('2017-06-2 ')); |
Sample code
The code is as follows: |
|
$ Date = date to be processed * $ Step 0 = this month, plus or minus the month date before and after this month * $ Date = Month to be processed * Enter description here... */ Function AssignTabMonth ($ date, $ step ){ $ Date = date ("Y-m-d", strtotime ($ step. "months", strtotime ($ date); // date after processing (get the date of the month before and after) $ U_date = strtotime ($ date ); $ Days = date ("t", $ u_date); // Number of days in the expected month // Date of the first day of the month $ First_date = date ("Y-m", $ u_date). '-01 '; For ($ I = 0; $ I <$ days; $ I ++ ){ $ For_day = date ("Y-m-d", strtotime ($ first_date) + ($ I * 3600*24 )); } Return $ first_date. 'to'. $ for_day; |
The following is the sample code of the week: // Obtain the function GetTheMonth ($ date) on the first and last days of the month of the specified date )...