1 //author:zhxia 获取指定日期所在星期的开始时间与结束时间
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['edate']=date('Y-m-d 23:59:59',$timestamp+(7-$w)*86400);
8 return $ret;
9 }
10
11 //author:zhxia 获取指定日期所在月的开始日期与结束日期
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['edate']=date('Y-m-'.$mdays.' 23:59:59',$timestamp);
18 return $ret;
19 }
20
21
22 //author:zhxia 以上两个函数的应用
23 function getFilter($n){
24 $ret=array();
25 switch($n){
26 case 1:// 昨天
27 $ret['sdate']=date('Y-m-d 00:00:00',strtotime('-1 day'));
28 $ret['edate']=date('Y-m-d 23:59:59',strtotime('-1 day'));
29 break;
30 case 2://本星期
31 $ret=getWeekRange(date('Y-m-d'));
32 break;
33 case 3://上一个星期
34 $strDate=date('Y-m-d',strtotime('-1 week'));
35 $ret=getWeekRange($strDate);
36 break;
37 case 4: //上上星期
38 $strDate=date('Y-m-d',strtotime('-2 week'));
39 $ret=getWeekRange($strDate);
40 break;
41 case 5: //本月
42 $ret=getMonthRange(date('Y-m-d'));
43 break;
44 case 6://上月
45 $strDate=date('Y-m-d',strtotime('-1 month'));
46 $ret=getMonthRange($strDate);
47 break;
48 }
49 return $ret;
50 }
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['edate']=date('Y-m-d 23:59:59',$timestamp+(7-$w)*86400);
8 return $ret;
9 }
10
11 //author:zhxia 获取指定日期所在月的开始日期与结束日期
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['edate']=date('Y-m-'.$mdays.' 23:59:59',$timestamp);
18 return $ret;
19 }
20
21
22 //author:zhxia 以上两个函数的应用
23 function getFilter($n){
24 $ret=array();
25 switch($n){
26 case 1:// 昨天
27 $ret['sdate']=date('Y-m-d 00:00:00',strtotime('-1 day'));
28 $ret['edate']=date('Y-m-d 23:59:59',strtotime('-1 day'));
29 break;
30 case 2://本星期
31 $ret=getWeekRange(date('Y-m-d'));
32 break;
33 case 3://上一个星期
34 $strDate=date('Y-m-d',strtotime('-1 week'));
35 $ret=getWeekRange($strDate);
36 break;
37 case 4: //上上星期
38 $strDate=date('Y-m-d',strtotime('-2 week'));
39 $ret=getWeekRange($strDate);
40 break;
41 case 5: //本月
42 $ret=getMonthRange(date('Y-m-d'));
43 break;
44 case 6://上月
45 $strDate=date('Y-m-d',strtotime('-1 month'));
46 $ret=getMonthRange($strDate);
47 break;
48 }
49 return $ret;
50 }