如何在PHP中显示日期范围

时间:2010-11-18 07:43:40

标签: php mysql datetime

我只是想知道如何在PHP中回显一系列日期

理想情况下,我希望系统能够在本周三周三到周三的周三显示

例如

17/11/1024/11/10

有人能指出我正确的方向吗?

5 个答案:

答案 0 :(得分:4)

$oBeginDate = new DateTime('last wednesday');
$oEndDate   = new DateTime('next wednesday');

echo $oBeginDate->format('d/m/Y') . ' to ' . $oEndDate->format('d/m/Y');

答案 1 :(得分:2)

我在你的问题中没有提到mysql,但如果你真的在谈论它:

select * from my_table where date_fld between '17/11/10' and '24/11/10'

答案 2 :(得分:1)

创建日期,并为其添加天数......

$m= date("m");
$de= date("d");
$y= date("Y");

for($i=0; $i<8; $i++){
  echo date('d-m-y:D',mktime(0,0,0,$m,($de+$i),$y));
  echo "<br>";
}

答案 3 :(得分:1)

使用strtotime

$now = '17/11/2010';
$next_week = date('d/m/Y', strtotime('+1 week', strtotime($now)));

答案 4 :(得分:1)

因为MySQL被标记了......

SELECT   now(), 
case
when weekday(now()) = 3 then date_sub(now(), interval 1 day)
when weekday(now()) = 2 then curdate()
when weekday(now()) = 1 then date_add(now(), interval 1 day)
when weekday(now()) = 0 then date_add(now(), interval 2 day)
when weekday(now()) = 4 then date_sub(now(), interval 1 day)
when weekday(now()) = 5 then date_sub(now(), interval 2 day)
when weekday(now()) = 6 then date_sub(now(), interval 3 day)
end as current_wednesday,
case
when weekday(now()) = 3 then date_add(now(), interval 6 day)
when weekday(now()) = 2 then date_add(now(), interval 7 day)
when weekday(now()) = 1 then date_add(now(), interval 8 day)
when weekday(now()) = 0 then date_add(now(), interval 9 day)
when weekday(now()) = 4 then date_add(now(), interval 5 day)
when weekday(now()) = 5 then date_add(now(), interval 4 day)
when weekday(now()) = 6 then date_add(now(), interval 3 day)
end as next_wednesday