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);
时间: 2024-10-12 20:28:13