2

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?

5 Answers 5

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

echo $oBeginDate->format('d/m/Y') . ' to ' . $oEndDate->format('d/m/Y');
Sign up to request clarification or add additional context in comments.

Comments

2

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'

2 Comments

wow you have thought ahead of me aha. but the dates would have to update each wednesday, they are not fixed.
... where date_fld between now() and now() + INTERVAL 1 WEEK
1

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>";
}

1 Comment

this works great but i would like it show only this week wednesday and next wednesday dates in this format: "17/11/10 to 24/11/10"
1

use strtotime

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

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.