I almost closed this as a duplicate of http://stackoverflow.com/questions/136782/format-mysql-datetime-with-php but I think it's actually the reverse problem. That question asked how to format a date fetched from MySQL, and you're asking how to format a date for input to a query.
Option 1:
SELECT * FROM MyTable WHERE DateTimeCol = ?
You can format the value to the YYYY-MM-DD HH:MM
format MySQL wants:
<?php $mysql_date = date('Y-m-d H:i:s', $timestamp); ?>
Then submit it as a string parameter to the query.
Option 2:
SELECT * FROM MyTable WHERE DateTimeCol = FROM_UNIXTIME(?)
Then you can submit the timestamp value as a numeric parameter to the query.
Option 3:
SELECT * FROM MyTable WHERE DateTimeCol = STR_TO_DATE(?, '%m/%d/%y')
You can submit a wide variety of string representations of date/time, if you specify the formatting to MySQL's STR_TO_DATE()
function. For the formatting codes, see the DATE_FORMAT()
function.