Jump to content

[SOLVED] How to insert DATEADD() into column?


fry2010

Recommended Posts

Ok what i have done so far is:

create a registered user.

When they register I use this to store the date they signed up:

 

 $result = $conn2->query("UPDATE useraccount SET joined = CURDATE() WHERE username = '$user'");

 

This works correctly.

Ok so now I want to add 7 days to this date and insert it in 'expire' column.

I want to do this at the same time that they join. I know that I could do this with about 3 seperate database queries but id rather do it with just one, or even two at most.

 

I have tried this:

 

 $result = $conn2->query("UPDATE useraccount SET joined = CURDATE(), expire = DATEADD(CURDATE(),INTERVAL 7 DAYS) WHERE username = '$user'");

 

But it doesnt work. I have also tried it with NOW().

 

Ok I managed to sort this out also.

I used this for anyone else thats stuck on it:

 

 $result = $conn2->query("UPDATE useraccount SET joined = CURDATE(), expire = DATE_ADD(joined, INTERVAL 7 DAY) WHERE username = '$user'");

 

Also the original problem from where all this started for me was because I was using PDO prepare and execute method for querying the date. But you cant do this because PDO will automatically quote out the input, so mysql will read it as a string, not a function.

Luckily my data isnt used from a user input form, so i can just use the standard query method.

I hate to have to do stuff when people put dates in a form.

 

I have a new problem now though. for anyone that sees this and can offer help I will be posting it in the php part as it relates to that.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.