您的位置:首页 > 编程语言 > PHP开发

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

2016-03-15 17:42 471 查看
<?php
/**
* 返回近7天,本月,上月数据
* 不计当天(展示后台数据专用)
*/
function weekMonthLastMonth($search_date = 'week') {

switch($search_date)
{
case 'week' : // 近7天
$start_date = date ("Y-m-d", strtotime("-7 days"));
$end_date = date ("Y-m-d", strtotime("-1 days"));
break;
case 'month' : // 本月
$start_date = date ("Y-m-01", strtotime("-1 days"));
$end_date = date ("Y-m-d", strtotime("-1 days"));
break;
case 'last_month' : // 上月
$search_time = strtotime ("-1 month");
$start_date = date ("Y-m-01", $search_time);
$end_date = date ('Y-m-d', strtotime("$start_date +1 month -1 day"));
break;
}
return array($start_date, $end_date);
}

echo print_r(weekMonthLastMonth('week'), true);
echo print_r(weekMonthLastMonth('month'), true);
echo print_r(weekMonthLastMonth('last_month'), true);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: