0

I am trying to update a MySQL table with current date into a column which type is DATE. current date structure is (2014-05-15). I've tried a few ways but it is not updating the date, however it is updating other fields.

MySQL query.

$q = "UPDATE TABLE SET
    DESCRIPTION     =".$db->qstr($string).",
        DATE        =".$db->qstr(date('Y-m-d')).",
    LAST_ACT        =".$db->qstr( time())."
    WHERE  ID=".$db->qstr( $id); 

I've tried DATE = DATE(NOW()), and DATE = DATE(), but it is not updating in MySQL,

Any suggestions?

3
  • Only date is not updating or the whole update query fails? And what does $db->qstr do? You'll also need quotes around your variables if they datatype is string.
    – asprin
    May 15, 2014 at 6:21
  • only date is not updating. others update fine May 15, 2014 at 6:22
  • What is the dataype of DATE column?
    – asprin
    May 15, 2014 at 6:28

3 Answers 3

2

Instead of DATE = DATE(NOW()). Try DATE = NOW()

1
  • I feel stupid to say but it was working all along, I was updating another database. Thanks everyone and sorry about my mistake. May 15, 2014 at 6:45
0

Try DATE=CURDATE() which will return a date data type. If that doesn't work, try doing some trial and error directly in the database console to see what works and what responses you get. And be sure and update us on the results.

3
  • In the code you posted there are no quotes around the right operands for your string and date types. I'm not sure how the description is being properly saved, but try this for date: DATE ='".$db->qstr(date('Y-m-d'))."',
    – Chad
    May 15, 2014 at 6:41
  • Or ... DATE=DATE_FORMAT(CURDATE(), '%Y-%m-%d')
    – Chad
    May 15, 2014 at 6:44
  • Thanks chad, all solutions worked!. see my reply above. sorry about this. May 15, 2014 at 6:48
0

It is very simple. Use now() function for it.

So it will be :

DATE = now()

1
  • Thanks for your reply. it was working all along. guess I got to double up on my coffee. I was updating a different table May 15, 2014 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.