|
Posted by Steve on 11/08/07 19:57
"Reg143" <Reg143@aol.com> wrote in message
news:Xns99E28F9944564Reg143aolcom@199.45.49.11...
> Hi all,
>
> The code below loops from a starting date, incrementing the date and
> displaying date and day-of-week. Everything is fine until 2007-11-04 is
> reached. Any help would be appreciated.
>
> Thanks in advance.
>
> ----------------------------------------------------
> Dates.php
> ----------------------------------------------------
>
> <?php
>
> // ----------------------------------
> // This code works until the date hits 2007-11-04, it
> // never gets past 11/4. Run it starting with the
> // different dates below. What gives?
> // ------------------------------------
why are you doing all that?
$date = strtotime('2007-11-04');
$dates = array();
for ($i = 0, $i < 7; $i++)
{
$dates[$i] = getdate(strtotime('+' . $i . ' day', $date));
}
foreach ($dates as $date)
{
$date[0] = date('Y-m-d', $date[0]);
echo '<pre>' .
date('Y-m-d', $date[0]) .
' is on a ' .
$date['weekday'] .
'</pre>';
}
in your example, you assume that every server you run your code on begins on
a monday - a zero index. that is entirely configurable. zero may very well
be a sunday on some systems. getdate() takes that configuration into
account. no need to build your own functions for any of that...just learn
what's at your desposal. checking the manual now and again surely helps. :)
[Back to original message]
|