Extracting DAY, MONTH and YEAR parts from a DATE

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 346
We can make use of YEAR(), MONTH() and DAY() datetime functions to extract date parts. Same output can be obtained by using DATEPART function

SELECT YEAR(GETDATE()) YearVal -- SAME AS DATEPART(YEAR, GETDATE())
, MONTH(GETDATE()) MonthVal -- SAME AS DATEPART(MONTH, GETDATE())
, DAY(GETDATE()) DayNumber -- SAME AS DATEPART(DAY, GETDATE())

SELECT DATEPART(YEAR, GETDATE()) YearVal
,DATEPART(MONTH, GETDATE()) MonthVal
,DATEPART(DAY, GETDATE()) DayNumber

Comments or Responses

Login to post response