Tabular IQ
Back to Function Index

HOUR()

Overview

HOUR() extracts the hour component from a date/time value, returning it as an integer between 0 and 23. This function is useful for time-based calculations, filtering, and reporting where you need to work with specific hours of the day.

Function Format

HOUR(date)

Return Value

HOUR() returns an integer between 0 and 23

Examples


HOUR(DATE(2025, 7, 4, 12, 30, 22))    = 12  (noon)
HOUR(DATE(2025, 12, 25, 8, 10, 20))   = 8   (morning)
HOUR(DATE(2025, 1, 1, 0, 0, 0))       = 0   (midnight)
HOUR(DATE(2025, 1, 1, 23, 59, 59))    = 23  (11 PM)
HOUR(DATE(2025, 1, 1, 15, 30, 0))     = 15  (3 PM)
HOUR(CURDATE())                       = 14  (if run at 2 PM)
HOUR(NULL)                            = NULL

Notes

  • The function returns an integer between 0 and 23, where:
    • 0 = Midnight (12 AM)
    • 12 = Noon (12 PM)
    • 23 = 11 PM
  • Common use cases include:
    • Time-based filtering
    • Business hour calculations
    • Time-based reporting
    • Schedule analysis
    • Time series analysis
  • The function can be used with any valid date/time expression, including:
    • Date literals
    • Date columns
    • Date functions
    • Date arithmetic expressions
  • If the input date is NULL, the function returns NULL.
  • This function is equivalent to EXTRACT(HOUR FROM date) in some database systems.
  • The function uses 24-hour format (0-23) rather than 12-hour format (1-12 AM/PM).

See Also