insert now plus a year

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

insert now plus a year

Post by GeXus »

How would you insert now() plus one year? In mysql... thanks!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

rswaby
Forum Newbie
Posts: 1
Joined: Mon Jul 02, 2007 7:46 pm

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

Post 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.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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
Post Reply