SQLTeam.com | Weblogs | Forums

Date in Ascending Order based on todays date


#1

Hi All,

I have calendar table and wanted to show the data in below fashion so that todays date will come first and then it will follow next dates.

So I will pass the where condition as Oct 2016 and expected result is

2016-10-13 00:00:00
2016-10-14 00:00:00
2016-10-15 00:00:00
2016-10-16 00:00:00
2016-10-17 00:00:00
2016-10-18 00:00:00
2016-10-19 00:00:00
2016-10-20 00:00:00
2016-10-21 00:00:00
2016-10-22 00:00:00
2016-10-23 00:00:00
2016-10-24 00:00:00
2016-10-25 00:00:00
2016-10-26 00:00:00
2016-10-27 00:00:00
2016-10-28 00:00:00
2016-10-29 00:00:00
2016-10-30 00:00:00
2016-10-31 00:00:00
2016-10-01 00:00:00
2016-10-02 00:00:00
2016-10-03 00:00:00
2016-10-04 00:00:00
2016-10-05 00:00:00
2016-10-06 00:00:00
2016-10-07 00:00:00
2016-10-08 00:00:00
2016-10-09 00:00:00
2016-10-10 00:00:00
2016-10-11 00:00:00
2016-10-12 00:00:00


#2
SELECT dateCol
FROM Calendar
ORDER BY CASE WHEN dateCol>=CAST(GETDATE() as date) 
THEN 1
ELSE 2 END, dateCol