Wednesday, 27 March 2013

How to retrieve Year / Month from Current or Any Datetime in SQL Server

Session 2 :


How to retrieve Year / Month from Current or Any Datetime ?


select 
[YEAR] = YEAR(getdate())
,[YEAR] = DATEPART(YY,getdate()) 
,[MONTH] = month(getdate())
,[MONTH] = DATEPART(mm,getdate())
,[MONTH NAME] = DATENAME(mm, getdate())


Output : -


YEAR YEAR MONTH    MONTH MONTH NAME
2013 2013 3            3                 March



No comments:

Post a Comment