Forum Moderators: coopster

Message Too Old, No Replies

Displaying dates for the week

Date, increment, tomorrow

         

Esqulax

4:17 pm on Jan 12, 2008 (gmt 0)

10+ Year Member



Hey guys, what's the best way to display todays date, then each successive day for say.. a week?

eg: an events diary:
1st ¦ 2nd ¦ 3rd

(if today was the 1st)
So that tomorrow, the dates would all be in line
Merci!

venelin13

4:37 pm on Jan 12, 2008 (gmt 0)

10+ Year Member



Oh, its easy when using strtotime() [php.net]


//start with an empty array, which will hold all of the next 7 days strings
$my_days = array();

//get the today date
$my_days[] = date("d/M/Y");

//get the next 6 days
for($i = 1; $i < 7; $i++){
//format each one of the next 6 days
$my_days[] = date("d/M/Y", strtotime("+{$i} day"));
}

//show the dates
echo implode(" ¦ ", $my_days);

Esqulax

4:45 pm on Jan 12, 2008 (gmt 0)

10+ Year Member



I see, Never knew about the strtotime function :p

Ill give it a go...

Esqulax

4:50 pm on Jan 12, 2008 (gmt 0)

10+ Year Member



Thanks, That code works great!

Is it wrong to enjoy coding?
Probably :p