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?
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?
... you can use it on any granularity type i.e.:
(note: I like the [ ] around the date reserved word though. Of course that's in case your column with timestamp is labeled "date")
The DATEPART() function is used to return a single part of a date/time, such as year, month, day, hour, minute, etc.
Example
There is a way to call
HOUR
(I would not recommend to use it though because there isDATEPART
function) using ODBC Scalar Functions:LiveDemo
DATEPART
documentationworks
to_char(current_timestamp,'YYYY') // to extract only DATE to_char(current_timestamp,'HH24') // to extract only HOUR