I am not sure on how your possibilities are,
but doing this in PHP means literally "adding useless lines and loops"

If possible, do it with SQL queries. Read the documentations on date
datatypes, this is so much easier... almost magic.


Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com




-----Original Message-----
From: Martin Skjoldebrand [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 22, 2001 4:15 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Incrementing dates


James, Yz wrote:

>If anyone has any comments on this, I'd like to
> hear
> them (there's probably a simpler way around what I have done).  Here's the
> URL:
>
> http://www.yorkshire-zone.co.uk/date_increment.php
>
> And here's the code that powers it:
>
> <HTML>
> <BODY>
>
> <?
>
> $date = date("2001-04-28");
> list($year, $month, $day) = explode("-", $date);
>
> $actual_date = mktime(0,0,0,$month,$day,$year);
>
> $days_to_add = 7;
>
> $x = 1;
>
> while($x <= $days_to_add) {
>
>  $make_date = getdate($actual_date);
>
>  echo "Day $x: $make_date[mday] $make_date[month],
> $make_date[year]<BR><BR>";
>
>  $actual_date = $actual_date + (3600 * 24);
>
>  $x++;
>
> }
>
> ?>
>
> </body>
> </html>

Thanks James!

You started me off in the right direction. And ... with a few beers less in
the brain (and a look at php.net and PHP Developers Cookbook) I finally
found that mktime actually increments dates correctly.
So, given that $month, $day and $year are valid and that we want to add 10
days to the output we can do:

echo date ("Y-m-d", mktime (0,0,0,$month, $day, $year)) . "<br>";
            for($i=1; $i<=9; $i++) {
              $day++;
              echo date ("Y-m-d", mktime (0,0,0,$month, $day, $year)) .
"<br>";
            }

Cheers,

Martin S.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to