One of the most asked questions in forums and discussion board is how a SQL function to extract year from date. This can be done in multiple ways as shown below.
SELECT YEAR(GETDATE()) AS [Year] GO SELECT CONVERT(varchar(4), GETDATE(), 126) AS [Year] GO SELECT DATEPART(YEAR,GETDATE()) AS [Year] GO SELECT DATEPART(YEAR,GETDATE()) AS [Year] GO SELECT DATENAME(YEAR,GETDATE()) AS [Year] GO -- available from SQL Server 2012 SELECT FORMAT(GETDATE(),'yyyy') AS [Year]
Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook