Richard is correct, the format for the mktime() is
hours/minutes/seconds/month/day/year. My code suggestion is based
on the start date being entered as follows -- 05242006, and the
display is to be 05/24/2006. My suggestion is the following...
function generateDates($first, $duration)
{
$dates = array();
$smonth = substr($first,0,2);
$sday = substr($first,2,2);
$syear = substr($first,4,4);
$start_date = mktime(0,0,0,$smonth,$sday,$syear);
for ($i = 1; $i <= $duration; $i++)
{
$added = mktime(0,0,0,$smonth,$sday+$i,$syear);
$dates[$i] = date( "m/d/Y", $added );
}
return $dates;
}
[SNIP]
Good luck,
Jef
-----Original Message-----
From: Richard Lynch [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 23, 2006 3:27 PM
To: Dave Goodchild
Cc: [email protected]
Subject: Re: [PHP] date iteration
mktime() args are hour/minute/second/month/day/year or somesuch.
You are passing in a string, which PHP tries to convert to int, which
results in who knows what, on the line that starts $added =
On Tue, May 23, 2006 6:11 am, Dave Goodchild wrote:
> Hi all, I am writing an app that runs a prize draw, wherein the admin
> chooses the duration by adding a start date and number of days for the
> draw
> to run. These values are passed into a small function that generates
> an
> array holding the start date, end date and all dates in between as
> follows:
>
> function generateDates($first, $duration) {
>
> $dates = array();
> $date = getdate(mktime($first));
> $month = $date['mon'];$day = $date['mday'];$year = $date['year'];
>
> for ($i = 1;$i <= $duration; $i++) {
>
> $added = getdate(mktime($day++ . "-" . $month . "-" . $year));
> $dates[] = $added['mday'] . "-" . $added['mon'] . "-" .
> $added['year'];
>
> }
> return $dates;
> }
>
>
> $series = generateDates('23-05-2006', 20);
> var_dump($series);
>
> ...when I var_dump the array the iteration stops at May 24 - I am
> looking
> into it but does anyone have any ideas why this is sticking ie is my
> date
> arithmetic wrong? Cheers.
>
> --
> http://www.web-buddha.co.uk
>
> dynamic web programming from Reigate, Surrey UK (php, mysql, xhtml,
> css)
>
> look out for project karma, our new venture, coming soon!
>
--
Like Music?
http://l-i-e.com/artists.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php