Day of the year function in tsql

is there a way to determine the day of the year given a date in sql server.  For example, 1/1/2007 would return 1, 2/1/2007 would return 32....

Who is Participating?
macentrapConnect With a Mentor Commented:
SELECT DATEPART(y, GETDATE()) AS 'Day of the Year'

SELECT DATEPART(y, '2007-12-02') AS 'Day of the Year'
you could use datediff to calculate the number of days between 1/1/2007 and the supplied date.
If not 2007 then take the year part of the supplied date and convert that to 1/1/yyyy
then use this to calculate
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.