php计算日,周,月起止时间

$date = "2022-09-18"

获取日

$firstday = date('Y-m-d', strtotime("$date +0 day"));
$lastday = date("Y-m-d", strtotime("$date +1 day"));

获取周

$lastday = date("Y-m-d", strtotime("$date Sunday"));
$firstday = date("Y-m-d", strtotime("$lastday -6 days"));

获取月

$firstday = date("Y-m-01", strtotime($date));
$lastday = date("Y-m-d", strtotime("$firstday +1 month -1 day"));

获取季度

$season = ceil(date('n',strtotime($date)) /3);
$firstday = date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
$lastday =  date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y')));
posted @ 2022-09-18 18:43  __、  阅读(50)  评论(0)    收藏  举报