Get month and year from a datetime in SQL Server 2005 Get month and year from a datetime in SQL Server 2005 sql sql

Get month and year from a datetime in SQL Server 2005


select datepart(month,getdate()) -- integer (1,2,3...),datepart(year,getdate()) -- integer,datename(month,getdate()) -- string ('September',...)


If you mean you want them back as a string, in that format;

SELECT   CONVERT(CHAR(4), date_of_birth, 100) + CONVERT(CHAR(4), date_of_birth, 120) FROM customers

Here are the other format options


Beginning with SQL Server 2012, you can use:

SELECT FORMAT(@date, 'yyyyMM')