PHP: example of getting the first day and last day of the month with the specified date _ PHP Tutorial

Source: Internet
Author: User
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 )...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.