JohnUS JohnUS - 1 month ago 4
MySQL Question

How to generate date for MySQL DATETIME type with PHP?

I need to get the records which are inserted in last 24 hours. I have read about it and got that I need to use

DATETIME
type in my MySQL date column.
But my problem is I don't know how to generate date for MySQL
DATETIME
type with PHP ?

How can I do this? Thanks in advance.

Answer

Simply

$mysql_date_now = date("Y-m-d H:i:s");

Because DATETIME in mysql is YYYY-MM-DD HH:ii:ss

Comments