views:

43

answers:

3

Hi All! ;-)

my question is:

assuming we have a calendar_table with UNIX datestamp date_column, i want retrieve the event with the closest proximity to the today date.

So, for example if there is no event today, keep the closest one based on it's date!

UPDATED

probably i need to be more clear, i need to retrieve not just one event, but All events in the table with the same date, closest to today date!

Thanks All you guys! ;-)

+2  A: 
SELECT *
FROM `calendar_table`
ORDER BY ABS(`date_column` - UNIX_TIMESTAMP()) DESC
LIMIT 1
soulmerge
hi soulmerge, thank's for responce, i have one question, what if i need to keep All not just 1 of event with the same date!?
aSeptik
+1 anyway for pointing me in a right way! ;-)
aSeptik
A: 
BrianCumminger
+3  A: 
SELECT * FROM `calendar_table` WHERE `date_column` = (SELECT `date_column` FROM `calendar_table` ORDER BY ABS(`date_column` - UNIX_TIMESTAMP()) ASC LIMIT 1)
Jesse Weigert
Thanks Jesse! it's exactly what i was looking for! a subquery is just perfect! i have just switched to **ASC** and it work fine!
aSeptik