Skip to content
Advertisement

Add Year to NOW()

I am trying to add a year to a date going into a SQL database from PHP. I have tried DATEADD(Year,1,NOW()) And various other forms but can’t seem to get it to add a year onto it in SQL.

<?php  

require ('includes/connect_db.php'); 

$q = "UPDATE users SET subdate = NOW() WHERE username = '{$_SESSION[username]}'";
$r = @mysqli_query ( $link, $q ) ;
# Close database connection.
# mysqli_close($link); 

?>

Thank you very very much!

Advertisement

Answer

You are attempting SQL Server syntax in MySQL.

In MySQL, you would simply do:

now() + interval 1 year

Or:

date_add(now(), interval 1 year)
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement