Help with dates

Hi,

I give up, I jus can’t work it out.

I have a table with 7 columns labelled Monday to Sunday.

I want to show todays date and 7 dates from today.
ie, Thurs 23rd
Fri 24th
Sat 25th
Sun 26th
Mon 27th
Tues 28th
Weds 29th

I imagine it’s easy when you know what you are doing. ???

Here you go,

[php]<?php
echo date(“D dS”);
echo “
”;
for($i=1;$i<7;$i++){
echo date(“D dS”,mktime(0, 0, 0, date(“m”) , date(“d”)+$i, date(“Y”)));
echo “
”;
}
?>
[/php]

Thanks. But I still don’t get it. The part I am having trouble with mostly is getting the dates to change in relation to the current day.

So on a Monday it would read the current week:
Mon 20th | Tues 21st | Wed 22nd | Thur 23rd | Fri 24th | Sat 25th | Sun 26th
But by Friday, the Mon to Thurs would be into the next week:
Mon 27th | Tues 28th | Wed 29th | Thur 30th | Fri 24th | Sat 25th | Sun 26th

I’m not getting you. Can be explain what exactly you want to achieve?

Sorry, I don’t quite know how to explain.

I have a single page timetable running Monday through to Sunday, which is fixed.

As each day passes, I need the dates to change for each day running from today for the next 6 days.
So today it would show:
Mon 27th | Tues 28th | Wed 29th | Thur 30th | Fri 24th | Sat 25th | Sun 26th
Then tomorrow:
Mon 27th | Tues 28th | Wed 29th | Thur 30th | Fri 1st | Sat 25th | Sun 26th
Then Sunday:
Mon 27th | Tues 28th | Wed 29th | Thur 30th | Fri 1st | Sat 2nd | Sun 26th
Then Monday:
Mon 27th | Tues 28th | Wed 29th | Thur 30th | Fri 1st | Sat 2nd | Sun 3rd

So only the date for each column would change.

Ok, I thought the best way to solve my problem was to put the dates into an array. This does exactly what I need when combined with 7 different if statements. How can I sort this in day order, so I can use echo $dates[0]; etc for each day?

<?PHP function createDatesArray($days) { $output = array(); $month = date("m"); $day = date("d"); $year = date("Y"); for($i=0; $i<=6; $i++){ $output[] = date('l jS M',mktime(0,0,0,$month,($day+$i),$year)); } return $output; } $dates = createDatesArray("7"); foreach($dates as $date) { echo($date . "
"); } ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service