Reputation: 1637
looking to organize the following dates (assuming today is August 24, 2012):
December 1, 2012
November 1, 2012
June 1, 2012
June 30, 2012
In the following way:
November 1, 2012
December 1, 2012
June 30, 2012
June 1, 2012
This is such a way that it shows the events that have NOT yet happened first, and from soonest to furthest away, then show past events, from closest to farthest.
You can assume the table structure is:
ID name event_date
1 Test 1351742400 # All dates are Unix Time
2 Test2 1354338000
Upvotes: 2
Views: 121
Reputation: 839194
SELECT ID, name, event_date
FROM yourtable
ORDER BY event_date < UNIX_TIMESTAMP(), ABS(UNIX_TIMESTAMP() - event_date)
See it working online: sqlfiddle
Upvotes: 3