Page 1 of 1

insert now plus a year

Posted: Sun Jul 01, 2007 8:22 pm
by GeXus
How would you insert now() plus one year? In mysql... thanks!

Posted: Sun Jul 01, 2007 8:25 pm
by feyd

How would you insert now() plus one year? In mysql... thanks

Posted: Mon Jul 02, 2007 8:05 pm
by rswaby
I'm not sure how you could do this in the insert statement but an easy way
to do it would be to get the current date then add 1 year to it store it in a
variable then insert that value such as:

Code: Select all

                 <?php 

                  //get the date for now
                   $now = date('Y-m-d');
                            
                 //get the date for 1 year from now
                   $newdate = mysql_query("SELECT Date_Add('$now', INTERVAL 1 Year) as newdate") or die("error". mysql_error());
                   $newdate_row = mysql_fetch_assoc($newdate);
                   $newdate_value = $newdate_row['newdate'];

                  ?>

                               


Then you could just simply use $newdate_value as the date 1 year from now that you would like to insert.
I'm sure you could work the Date_Add function into your insert statement but thats too messy for me
to work out in my head.

Posted: Tue Jul 03, 2007 4:29 am
by miro_igov
8O 8O 8O How about

Code: Select all

INSERT INTO table SET `date`= DATE_ADD(NOW(), INTERVAL 1 YEAR)
Messy is to do all these things to get $newdate_value