DATEPART(), How to get any Part of Date ex Day, Month or Year?

Aman Sharma

 DATEPART(): This function is used get a particular part of date i.e. Day, month, year. It will return the part of date or time.


DATEPART(datepart, datecolumn)

Get Hour from given Datetime in SQL:
Select DATEPART(HOUR, GETDATE()) as CurrentHour

Result: 11

Get Day from Date in SQL:

Select DATEPART(DAY, GETDATE()) as CurrentDay

Result: 25

Get Month from Date in SQL:

Select DATEPART(MONTH, GETDATE()) as CurrentMonth

Result: 3

Get Year from Date in SQL:

Select DATEPART(YEAR, GETDATE()) as CurrentYear

Result: 2020

Post a Comment

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !