扫码关注官方订阅号
当前日期是【2016/06/14 周二】
那么上周的时间区间就是【2016/06/06】-【2016/06/12】
只有当前日期没有完成(就是本周周日没过完)
那么上周就会一直是【2016/06/06】-【2016/06/12】
求php如何获取上周的时间区间
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
用strtotime,详情自己查手册吧。例子 date('Y-m-d', strtotime('-1 week'))得到当前时间前一周,月份也是date('Y-m-d', strtotime('-1 month')),天、年也都可以。
date('Y-m-d', strtotime('-1 week'))
date('Y-m-d', strtotime('-1 month'))
echo date("Y-m-d",strtotime('-1 week last monday'))." 00:00:00";echo date("Y-m-d",strtotime('last sunday'))." 23:59:59";
echo date("Y-m-d",strtotime('-1 week last monday'))." 00:00:00";
echo date("Y-m-d",strtotime('last sunday'))." 23:59:59";
echo '<br>上周起始时间:<br>'; echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n"; echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
用strtotime,详情自己查手册吧。例子
date('Y-m-d', strtotime('-1 week'))得到当前时间前一周,月份也是date('Y-m-d', strtotime('-1 month')),天、年也都可以。echo date("Y-m-d",strtotime('-1 week last monday'))." 00:00:00";echo date("Y-m-d",strtotime('last sunday'))." 23:59:59";