在php里面怎么做日期范围,如何在php中获得上周的日期范围?
你可以使用
strtotime()
$previous_week = strtotime("-1 week +1 day");
$start_week = strtotime("last sunday midnight",$previous_week);
$end_week = strtotime("next saturday",$start_week);
$start_week = date("Y-m-d",$start_week);
$end_week = date("Y-m-d",$end_week);
echo $start_week.' '.$end_week ;
UPDATE
更改代碼以處理星期日.如果當天是星期天,那么 – 1周將是上個星期日,并且再次獲得上一個星期日,那將是一周之后.
$previous_week = strtotime("-1 week +1 day");
In addition if we need to find the current week and next week date
range we can do as
這個星期 –
$d = strtotime("today");
$start_week = strtotime("last sunday midnight",$d);
$end_week = strtotime("next saturday",$d);
$start = date("Y-m-d",$start_week);
$end = date("Y-m-d",$end_week);
下周 –
$d = strtotime("+1 week -1 day");
$start_week = strtotime("last sunday midnight",$d);
$end_week = strtotime("next saturday",$d);
$start = date("Y-m-d",$start_week);
$end = date("Y-m-d",$end_week);
總結
以上是生活随笔為你收集整理的在php里面怎么做日期范围,如何在php中获得上周的日期范围?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php发送验证图片,php生成图片验证码
- 下一篇: php获取python的变量,PHPPy