欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP获取今日、昨日、本周、上周、本月、上月、本季、上季、今年、去年

程序员文章站 2023-01-20 20:45:10
//今天开始$beginToday = date('Y-m-d 00:00:00', time());//今天结束$endToday = date('Y-m-d 23:59:59', time()); //昨天开始$beginYesterday = date('Y-m-d 00:00:00', st ......

//今天开始
$begintoday = date('y-m-d 00:00:00', time());
//今天结束
$endtoday = date('y-m-d 23:59:59', time());

//昨天开始
$beginyesterday = date('y-m-d 00:00:00', strtotime(' -1 day'));
//昨天结束
$endyesterday = date('y-m-d 23:59:59', strtotime(' -1 day'));

//本周开始,周一开始
$beginthisweek = date('y-m-d 00:00:00', strtotime('this week monday'));
//本周结束,周日结束
$endthisweek = date('y-m-d 23:59:59', strtotime('this week sunday'));

//上周开始,周一开始
$beginlastweek = date('y-m-d 00:00:00', strtotime('last week monday'));
//上周结束,周日结束
$endlastweek = date('y-m-d 23:59:59', strtotime('last week sunday'));

//本月开始
$beginthismonth = date('y-m-01 00:00:00');
//本月结束
$endthismonth = date('y-m-d 23:59:59', strtotime('last day of this month'));

//上月开始
$beginlastmonth = date('y-m-01 00:00:00', strtotime('last month'));
//上月结束
$endlastmonth = date('y-m-d 23:59:59', strtotime('last day of last month'));

//本季度开始
$beginthisseason = date('y-m-01 00:00:00', strtotime((1 - (date('n') % 3 == 0 ? 3 : date('n') % 3)) . ' month'));
//本季度结束
$endthisseason = date('y-m-d 23:59:59', strtotime('last day of' . (3 - (date('n') % 3 == 0 ? 3 : date('n') % 3)) . ' month'));

//上季度开始
$beginlastseason = date('y-m-01 00:00:00', strtotime((-2 - (date('n') % 3 == 0 ? 3 : date('n') % 3)) . ' month'));
//上季度结束
$endlastseason = date('y-m-d 23:59:59', strtotime('last day of' . (- (date('n') % 3 == 0 ? 3 : date('n') % 3)) . ' month'));

//本年度开始
$beginthisyear = date('y-01-01 00:00:00');
//本年度结束
$endthisyear = date('y-12-31 23:59:59');

//上年度开始
$beginlastyear = date('y-01-01 00:00:00', strtotime('last year'));
//上年度结束
$endlastyear = date('y-12-31 23:59:59', strtotime('last year'));