user3620142
user3620142

Reputation: 145

How to update mysql with current date with php?

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?

Upvotes: 0

Views: 3201

Answers (3)

The_Geek
The_Geek

Reputation: 31

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

So it will be :

DATE = now()

Upvotes: 0

droymanz
droymanz

Reputation: 343

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

Upvotes: 2

Chad
Chad

Reputation: 164

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.

Upvotes: 0

Related Questions