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

Source: Internet
Author: User
1 // author: zhxia obtains the start time and end time of the week of the specified date.
2 function getWeekRange ($ date ){
3 $ ret = array ();
4 $ timestamp = strtotime ($ date );
5 $ w = strftime ('% U', $ timestamp );
6 $ ret ['sdate'] = date ('Y-m-d 00:00:00 ', $ timestamp-($ W-1) * 86400 );
7 $ ret ['update'] = date ('Y-m-d 23:59:59 ', $ timestamp + (7-$ w) * 86400 );
8 return $ ret;
9}
10
11 // author: zhxia obtains the start date and end date of the month where the specified date is located.
12 function getMonthRange ($ date ){
13 $ ret = array ();
14 $ timestamp = strtotime ($ date );
15 $ mdays = date ('T', $ timestamp );
16 $ ret ['sdate'] = date ('Y-M-1 00:00:00 ', $ timestamp );
17 $ ret ['update'] = date ('Y-m-'. $ mdays. '23:59:59', $ timestamp );
18 return $ ret;
19}
20
21
22 // author: application of the two functions above zhxia
23 function getFilter ($ n ){
24 $ ret = array ();
25 switch ($ n ){
26 case 1: // Yesterday
27 $ ret ['sdate'] = date ('Y-m-d 00:00:00 ', strtotime ('-1 Day '));
28 $ ret ['update'] = date ('Y-m-d 23:59:59 ', strtotime ('-1 Day '));
29 break;
30 case 2: // this week
31 $ ret = getWeekRange (date ('Y-m-d '));
32 break;
33 case 3: // last week
34 $ strDate = date ('Y-m-d', strtotime ('-1 week '));
35 $ ret = getWeekRange ($ strDate );
36 break;
37 case 4: // last week
38 $ strDate = date ('Y-m-d', strtotime ('-2 week '));
39 $ ret = getWeekRange ($ strDate );
40 break;
41 case 5: // this month
42 $ ret = getMonthRange (date ('Y-m-d '));
43 break;
44 case 6: // last month
45 $ strDate = date ('Y-m-d', strtotime ('-1 month '));
46 $ ret = getMonthRange ($ strDate );
47 break;
48}
49 return $ ret;
50}

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.