How to use the YEAR, MONTH and DAY functions?
How to use the YEAR, MONTH and DAY functions? Execute the following Microsoft SQL Server T-SQL scripts in SSMS Query Editor to demonstrate the application of Year, Month and Day datetime functions. -- T-SQL Year, Month & Day functions DECLARE @Date datetime = '2018-03-15' -- SQL Server Year function SELECT YYYY = YEAR ( @Date ) SELECT YYYY = DATEPART ( yy , @Date ) -- 2018 -- SQL Server Month function SELECT MM = MONTH ( @Date ) SELECT MM = DATEPART ( mm , @Date ) -- 3 -- SQL Server Day function SELECT DD = DAY ( @Date ) SELECT DD = DATEPART ( dd , @Date ) -- 15