0

I have searched everywhere but I cant find anyone else experiencing this

When I run this in MySQL (via phpmyadmin) it works fine

 UPDATE users SET timetoken=DATE_ADD((now()), INTERVAL 1 HOUR) WHERE username='usman'

And then this is my php

 mysqli_query($con,"UPDATE users SET timetoken=DATE_ADD((now()), INTERVAL 5 HOUR) WHERE username='usman'");

It will update the field, but oddly enough it changes the date to the current time and does not add the hours

Can anyone help?

  • 1
    Do `DATE_ADD(NOW( ), INTERVAL 1 HOUR)` - One set of brackets too many. Or `DATE_ADD(NOW( ), INTERVAL 5 HOUR)` – Funk Forty Niner Nov 08 '14 at 02:02
  • Please also read http://stackoverflow.com/a/8437328/1164491 and http://stackoverflow.com/a/12670065/1164491 – Cheery Nov 08 '14 at 02:10
  • Thanks for your reply; I just tried that and it still reports the current date instead of adding the interval....the query must be running since it updates the field to the current date I just dont know why it wont add the 5 hours...any ideas? – user3666791 Nov 08 '14 at 02:14
  • Thanks for your reply @Cheery - I took those links as maybe its retreiving the date in phpmyadmin but not in php, so I changed NOW() to $currentdate = date("Y-m-d h:i:s") - so that PHP and not MYSQL was generating the date; and it still did not work :-( – user3666791 Nov 08 '14 at 02:34

1 Answers1

0

Try:

// Set $q to sql query
$q = "UPDATE users SET timetoken = DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 5 HOUR) WHERE username = 'usman'";

// Execute query
mysqli_query($con, $q);
visigoth
  • 208
  • 1
  • 8
  • Thanks for your response; When I run the query it still updates with the current time.... I just ran the following query with both NOW() and CURRENT_TIMESTAMP $s = mysqli_query($con, "SELECT CURRENT_TIMESTAMP AS P"); $p = mysqli_fetch_object($s); $p = $s->P; And it did not retrieve anything...So I'm guessing that has to be the problem? – user3666791 Nov 08 '14 at 02:31
  • Sorry - see previous comment, hit enter too early. – user3666791 Nov 08 '14 at 02:33
  • Ok, can I see your table structure? Maybe the timetoken is not in the format it should be to reflect hours, maybe it's just a date format; you need DATETIME – visigoth Nov 08 '14 at 02:35
  • Oh my god - THANK YOU SO MUCH. I've spent 5 HOURS (straight) on this, it was set to time_stamp and not DATETIME so stupid. – user3666791 Nov 08 '14 at 02:39
  • Im new to stack overflow how do I select this as the correct answer? Thank you so much, if there is anything I can do for you please LET ME DO IT. Thanks again!!!! – user3666791 Nov 08 '14 at 02:40
  • I don't know, I'm new too lol! I just made an account to answer questions because I think its fun helping people out here. Well, find out how to do it because I dont' know how! xD have a good one. – visigoth Nov 08 '14 at 02:43