How to get only hour from getdate() function in sql server

select datepart(hour,getdate()) as [hours]

DatePart Function will retrieve part of the date.

DATEPART(part, datetime)

Ms for Milliseconds
Yy for Year
Qq for Quarter of the Year
Mm for Month
Dy for the Day of the Year
Dd for Day of the Month
Wk for Week
Dw for the Day of the Week
Hh for Hour
Mi for Minute
Ss for Second

You can replace part with the any of the part in the specified above items.

For example, for hours:


Leave a Reply

Your email address will not be published. Required fields are marked *