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


//今天開始
$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'));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM