ADD DAYS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phppick
Forum Commoner
Posts: 57
Joined: Thu Aug 14, 2003 5:59 am

ADD DAYS

Post by phppick »

I Want to add 30 days to the Current Date. How can i do it?
I got some Date Class in NET but, i don't know how to use it.
Can anybody give me answer??

Thanks
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

[php_man]explode[/php_man]
[php_man]date[/php_man]
[php_man]mktime[/php_man]

Code: Select all

$date=date("Y-m-d");
 list($year,$month,$day)=explode("-",$date);
 $month_after=date("Y-m-d",mktime(0,0,0,$month,$day+30,$year));
 echo $month_after."\n";
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Or just:

Code: Select all

<?php
    echo date("Y-m-d",mktime (0,0,0,date("m")  ,date("d")+10,date("Y")));
?>
Chambrln
Forum Commoner
Posts: 43
Joined: Tue Dec 02, 2003 10:45 am
Location: Oregon

Post by Chambrln »

Or if you are actually wanting to add a month where months change from 30-31 and even 28 at times you should just do

Code: Select all

<?php
echo date("Y-m-d",mktime (0,0,0,date("m")+1,date("d"),date("Y")));
?>
Post Reply