PHP 返回近7天 本月 上月日期

 1 <?php
 2 /**
 3  * 返回近7天,本月,上月数据
 4  * 不计当天(展示后台数据专用)
 5  */
 6 function weekMonthLastMonth($search_date = 'week') {
 7 
 8     switch($search_date)
 9     {
10         case 'week' : // 近7天
11             $start_date = date ("Y-m-d", strtotime("-7 days"));
12             $end_date = date ("Y-m-d", strtotime("-1 days"));
13             break;
14         case 'month' : // 本月
15             $start_date = date ("Y-m-01", strtotime("-1 days"));
16             $end_date = date ("Y-m-d", strtotime("-1 days"));
17             break;
18         case 'last_month' : // 上月
19             $search_time = strtotime ("-1 month");
20             $start_date = date ("Y-m-01", $search_time);
21             $end_date = date ('Y-m-d', strtotime("$start_date +1 month -1 day"));
22             break;
23     }
24     return array($start_date, $end_date);
25 }
26 
27 echo print_r(weekMonthLastMonth('week'), true);
28 echo print_r(weekMonthLastMonth('month'), true);
29 echo print_r(weekMonthLastMonth('last_month'), true);

 

posted @ 2016-03-15 17:42  cloudshadow  阅读(394)  评论(0编辑  收藏  举报