Closest Match to timestamp

I have a DB where a field called date which has a timestamp and i am trying to sort delivery reports for sms.

the incoming delivery report has a timestamp which is normally around 30 seconds out or may be more.

how would i find the closest match to the report timestamp?

SELECT `date`, '2015-06-29 20:03:23' AS SMSTIME FROM history ORDER BY ABS(`date` - SMSTIME) ASC LIMIT 1 does not bring back the correct day or time

found a fix that looks like i should of thought of it before!!

SELECT * FROM `history` WHERE `to` LIKE '077777777777' AND `date` <= '2015-06-29 20:03:23' ORDER BY `history`.`date` DESC LIMIT 1

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.