Jump to content

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


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.

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.