1

I'm trying to update my datetime field in a table with the following PHP datetime:

$datetime = date('d/m/Y H:i:s');

Unfortunately the datetime field in the table is NULL

How can I update a datetime field with $datetime ?

Thanks

3 Answers 3

4

right format is Y-m-d H:i:s anyway in your SQL query you can use NOW()

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_now

Sign up to request clarification or add additional context in comments.

1 Comment

You can also instead of now() use current_timestamp in mysql query.
2
$datetime = date('Y-m-d H:i:s');

will work. DATETIME columns must be in a Y-m-d H:i:s format, not d-m-Y H:i:s.

From the manual:

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format.

Comments

1

The correct format is Y-m-d H:i:s.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.