HOUR returns the hour portion of a value.

Syntax

HOUR ( expression )

Arguments

expression: a DATE, TIMESTAMP, or non-LONG VARCHAR string value that is properly formatted to represent a DATE or TIMESTAMP.

Returns

  • An INTEGER for the hour, between 0 and 23. Returns NULL if expression is NULL.

Examples

SELECT orderDate, HOUR(orderDate) AS orderDateHour FROM MYSQL.inventory.cust;

VALUES HOUR(CAST('2012-06-20 15:23:45' AS TIMESTAMP))
-- Returns 15