Extracting hours from a DateTime (SQL Server 2005)

Efe picture Efe · Jul 11, 2009 · Viewed 553.7k times · Source

I can extract the month and day by using Day(Date()), Month(Date()). I can't extract hours, with HOUR(Date()). I get the following error.

'HOUR' is not a recognized built-in function name.

How can I extract hours?

Answer

Dave Markle picture Dave Markle · Jul 11, 2009
SELECT DATEPART(HOUR, GETDATE());

DATEPART documentation