I’m storing a date column using time() (php function).
My date column has a int data type since i’m using time() php function.
This is a sample:
date
1317957366
1318043891
My question is, how would I query or create a logic that would get a result who has a time that is nearest on today’s time?
I want to query it via mysql not on the php logic, but if you have suggestion that I should do it on php, then that would also be fine.
Thanks and your help would be greatly appreciated and rewarded. 🙂
Compare the absolute value of the current time – the stored time, and select the
MIN()of those:Perhaps something like this?
If that doesn’t work properly, try with a subquery:
Since you have stored the dates as
INTinstead of as MySQLDATETIME, you need to convert the current timestampNOW()to a Unix timestamp, then subtract the storeddate.