1.获取本周开始和结束的日期:
echo date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y"))); //2020-03-09 00:00:00
echo date("Y-m-d H:i:s", mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))); //2020-03-15 23:59:59
2.获取上周开始和结束的日期:
echo date('Y-m-d H:i:s', mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'))); //2020-03-02 00:00:00
echo date('Y-m-d H:i:s', mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'))); //2020-03-08 23:59:59
3.获取本月开始和结束的日期:
echo date('Y-m-d H:i:s', mktime(0,0,0,date('m'),1,date('Y'))); //2020-03-01 00:00:00
echo date('Y-m-d H:i:s', mktime(23,59,59,date('m'),date('t'),date('Y'))); //2020-03-31 23:59:59
4.获取上月开始和结束的日期:
echo date("Y-m-d H:i:s", mktime(0,0,0,date("m")-1,1,date("Y"))); //2020-02-01 00:00:00
echo date("Y-m-d H:i:s", mktime(23,59,59,date("m") ,0,date("Y"))); //2020-02-29 23:59:59
5.获取本季度开始和结束的日期:
$season = ceil((date('n'))/3);
echo date('Y-m-d H:i:s', mktime(0,0,0,$season*3-3+1,1,date('Y'))); //2020-01-01 00:00:00
echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0,0,0,$season*3,1,date("Y"))),date('Y'))); //2020-03-31 23:59:59
6.获取上季度开始和结束的日期:
$season = ceil((date('n'))/3)-1;//上季度是第几季度
echo date('Y-m-d H:i:s', mktime(0,0,0,$season*3-3+1,1,date('Y'))); //2019-10-01 00:00:00
echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0,0,0,$season*3,1,date("Y"))),date('Y')));//2019-12-31 23:59:59
7.获取本月是第几月:
echo date('n'); //3
8.获取今天是周几:
echo date("w"); //4
9.获取本月总天数:
echo date("t"); //31
本文转至:https://blog.csdn.net/weixin_42546392/article/details/115967678
评论