PHP get the date range of the current week (month) _ PHP Tutorial

Source: Internet
Author: User
PHP obtains the date range of the current week (month. PHP needs to get the date range of the current week (month), and write a date range to get the current week, that is, from Monday to Sunday. FunctiongetWeekRang PHP gets the date range of the current week (month)

The program needs to write a date range for obtaining 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-M-1 00:00:00 ', $ timestamp );

$ Ret ['update'] = date ('Y-m-'. $ mdays. '23:59:59', $ timestamp );

Return $ ret;

}

// Author: application of the preceding two functions of zhxia

Function getFilter ($ n ){

$ Ret = array ();

Switch ($ n ){

Case 1: // yesterday

$ Ret ['sdate'] = date ('Y-m-d 00:00:00 ', strtotime ('-1 DAY '));

$ Ret ['update'] = date ('Y-m-d 23:59:59 ', strtotime ('-1 DAY '));

Break;

Case 2: // this week

$ 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: // this month

$ 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;

}

The date range program of week (month) needs to write a date range to obtain the current week, that is, the date range from Monday to Sunday. Function getWeekRang...

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.