How to generate date for MySQL DATETIME type with PHP?

Simply

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

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


If you are looking just for a way to generate the datetime to insert into the datetime field just use the following code

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

or for the direct sql

INSERT INTO {TABLE} ({DATETIME}) VALUES (NOW())

This will create a date that looks like

2012-02-28 16:44:25

If you are looking for the query to get the last 24 hours use

SELECT * FROM tablename WHERE date_field > NOW() - interval 1 day