获取上周的日期范围,周一到周日

时间:2016-06-24 05:28:08

标签: php

使用Php日期函数我想得到上周的日期范围,

例如。

2016年6月24日星期五今天。

我想要出局

上周开始日期:2016-06-13(YYYY-mm-dd格式)

上周结束日期:2016-06-19(YYYY-mm-dd格式)

这可能吗?

4 个答案:

答案 0 :(得分:4)

<?php
 echo date("Y-m-d", strtotime("last week monday"));
 echo "<br>";
echo date("Y-m-d", strtotime("last sunday"));
?>

答案 1 :(得分:3)

只需使用strtotime功能:

echo date("Y-m-d",strtotime('sunday',strtotime('last week'))); //2016-06-19
echo date("Y-m-d",strtotime('monday',strtotime('last week'))); //2016-06-13

答案 2 :(得分:0)

尝试:

$start_week = strtotime("last monday midnight");
$end_week = strtotime("+1 week",$start_week);

$start_week = date("Y/m/d",$start_week);
$end_week = date("Y/m/d",$end_week);

echo $start_week.' '.$end_week ;

答案 3 :(得分:0)

是的,有可能。使用strtotime()
Date formats

strtotime('sunday', 'Fri June 24th, 2016"')
strtotime('monday', 'Fri June 24th, 2016"')

相关问题