How to use PHP to obtain the start date and end date of the month where the specified date is located
Source: Internet
Author: User
The following is a detailed analysis of PHP implementation code for obtaining the start date and end date of the month with the specified date. For more information, see
The code is as follows:
/**
* Obtain the start and end dates of the month of the specified date.
* @ Param string $ date
* @ Param boolean: true. The start date is returned. Otherwise, the end date is returned.
* @ Return array
* @ Access private
*/
Private function getMonthRange ($ date, $ returnFirstDay = true ){
$ Timestamp = strtotime ($ date );
If ($ returnFirstDay ){
$ MonthFirstDay = date ('Y-M-1 00:00:00 ', $ timestamp );
Return $ monthFirstDay;
} Else {
$ Mdays = date ('t', $ timestamp );
$ MonthLastDay = date ('Y-m-'. $ mdays. '23:59:59', $ timestamp );
Return $ monthLastDay;
}
}
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.