DayOfYear function in T-SQL / SQL Server 2000

Tim picture Tim · Sep 21, 2012 · Viewed 20.4k times · Source

2 FEB is the 33rd day of the year, for example.

Is there a built-in T-SQL function that returns the day-of-year (in SQL Server 2000)? Or do you have to roll your own using casts to get the first day of the year for the supplied date, and then do a DateDiff?

Answer

SELECT datepart(dayofyear, getdate())