how to display range of dates in PHP
I was just wondering how you can echo a range of dates in PHP
ideally i want the system to display this week wednesday to next week开发者_运维问答 wednesday
for example
17/11/10
to 24/11/10
can anyone point me in the right direction?
$oBeginDate = new DateTime('last wednesday');
$oEndDate = new DateTime('next wednesday');
echo $oBeginDate->format('d/m/Y') . ' to ' . $oEndDate->format('d/m/Y');
i see no mention about mysql in your question, but if you're really talking about it:
select * from my_table where date_fld between '17/11/10' and '24/11/10'
create a date, and add days to it...
$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>";
}
use strtotime
$now = '17/11/2010';
$next_week = date('d/m/Y', strtotime('+1 week', strtotime($now)));
Since MySQL is tagged...
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
精彩评论