PHP obtains the start date and end date of the week (month) of the current date.

Source: Internet
Author: User
PHP obtains the start date and end date of the week (month) of the current date. it obtains the start time and end time of the week of the specified date. functiongetWeekRange ($ date) {$ retarray (); $ timestampstrtotime ($ date); $ wstrftime (% u, $ timestamp); $ re PHP gets the start and end dates 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 ;}

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.