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}