This question already has an answer here:
my MYSQL table is as below:
id record_nr timestamp
1 931 2014-02-15 6:21:00
2 577 2013-05-03 0:19:00
3 323 2012-08-07 11:26:00
in PHP I tried to retrieve a record by comparing time as below:
$dateTimeString = "2013-07-28 7:23:34";
$query = "SELECT * FROM mytable ";
$query .= "WHERE timestamp <= STR_TO_DATE('".$dateTimeString."', '%H:%i:%s')";
$query .= " ORDER BY timestamp DESC LIMIT 1";
This didn't work. How to retrieve the record #577? Timestamp is not the time the record was created. Rather, it is a date and time associated with that record.
</div>
Below code can be helpful:
$dateTimeString = '2016-12-27 12:59:46';
$query = "SELECT * FROM `mytable`
WHERE `TIMESTAMP` <= '".$dateTimeString."'
ORDER BY TIMESTAMP DESC LIMIT 1";
I changed to
$query .= "WHERE timestamp <= '".$dateTimeString."'";
It seems to work. Thanks.