insert now plus a year
Moderator: General Moderators
insert now plus a year
How would you insert now() plus one year? In mysql... thanks!
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
viewtopic.php?t=69840&highlight=interval+year may be of interest.
How would you insert now() plus one year? In mysql... thanks
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:
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.
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.
Code: Select all
INSERT INTO table SET `date`= DATE_ADD(NOW(), INTERVAL 1 YEAR)