Jump to content

Update DATE field by adding 1 year


sh0wtym3

Recommended Posts

I'm working on a script that will add 1 year to the date, but it doesn't seem to work and I can't figure out why. Here is my code:

 

<?php
$conn = mysql_connect("localhost","username","password");
mysql_select_db("database");

$id = $_GET['id'];

$sql = "UPDATE table SET year = date_add(mydate, INTERVAL 1 YEAR) WHERE id = '$id'";
$res = mysql_query($sql, $conn);
?>

 

"mydate" is the name of the column with the dates, and the field type for that column is set to date.

 

Thanks in advance!

Link to comment
Share on other sites

I just ran your almost exact code on my database via phpmyadmin and it worked properly

 

UPDATE counter SET datestamp = date_add(datestamp, INTERVAL 1 YEAR) WHERE id = '5';

 

counter is the table

datestamp is the name of the column which is type date

id is the unique identifier

 

When I ran this it updated my field from

 

2008-04-19

 

to

 

2009-04-19

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.