RE: [PHP] Incrementing dates
| From: | PHPBeginner.com | Date: | Sun, 22 Apr 2001 08:16:39 +0000 |
| Subject: | RE: [PHP] Incrementing dates | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-49730@lists.php.net to get a copy of this message | ||
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)
maxim@phpbeginner.com
www.phpbeginner.com
-----Original Message-----
From: Martin Skjoldebrand [mailto:chimbis@skjoldebrand.org]
Sent: Sunday, April 22, 2001 4:15 PM
To: php-general@lists.php.net
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: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net