How to get Day of Year from date in SQL Server

Share this blog:
  •  
  •  
  •  
  •  
  •  

Method #1: Using DATEPART Function

SELECT GETDATE() 'Today', DATEPART(dayofyear,GETDATE()) [Day_of_Year]
SELECT GETDATE() 'Today', DATEPART(dy,GETDATE()) [Day_of_Year]
SELECT GETDATE() 'Today', DATEPART(y,GETDATE()) [Day_of_Year

Method #2: Using DATENAME Function

SELECT GETDATE() 'Today', DATENAME(dayofyear,GETDATE()) [Day_of_Year]
SELECT GETDATE() 'Today', DATENAME(dy,GETDATE()) [Day_of_Year]
SELECT GETDATE() 'Today', DATENAME(y,GETDATE()) [Day_of_Year]

Leave a Reply

Your email address will not be published. Required fields are marked *

seventeen − 8 =