How do I query a table with a DATETIME column using the following conditions:
select all transactions
from 2007-02-21 14:01:00 to 2007-02-22 14:00:00
Thnx
If it's MS SQL then the following statement would work ;
$sql = "SELECT * FROM TABLE_NAME WHERE (DATE_FIELD >= CONVERT(DATETIME, '2007-02-21 14:01:00', 102)) AND (DATE_FIELD <= CONVERT(DATETIME, '2007-02-22 14:00:00', 102))"
This should work in MySQL:
$from = '2007-02-21 14:01:00'; $to = '2007-02-22 14:00:00'; $query = "SELECT * FROM table_name WHERE date_field BETWEEN '$from' AND '$to'";