Skip to main content
Version: Java (Groovy)

hourOfDay

hourOfDay returns an int representing the hour of the input date-time. Hours are from 0-23, with times between midnight and 1AM on a given day returning the hour 0.

note

On days when daylight savings time events occur, results may be different from what is expected based upon the local time. For example, on daylight savings time change days, 9:30AM may be earlier or later in the day based upon if the daylight savings time adjustment is forwards or backwards.

Syntax

hourOfDay(instant, timeZone, localTime)
hourOfDay(dateTime, localTime)
hourOfDay(localTime)

Parameters

ParameterTypeDescription
instantInstant

The time for which to find the hour of the day.

timeZoneTimeZones The time zone to use when interpreting the [date-time](/core/groovy/docs/reference/query-language/types/date-time).
dateTimeZonedDateTime

The zoned date-time for which to find the hour of the day.

localTimeboolean

Set this parameter to false if you need Deephaven to account for daylight savings time.

  • If false, returns the number of hours from the start of the day. However, on days when daylight savings time events occur, results may be different from what is expected based on the local time. For example, on DST change days, 9:30 AM may be earlier or later in the day based on whether the daylight savings time adjustment is forward or backward. On non-DST days, the result is the same as if localTime is false.
  • If true, returns the number of hours from the start of the day according to the local time. In this case, 9:30 will always return the same value.

Returns

Returns a 0-based int value of the hour of the day.

Examples

datetime = parseInstant("2024-02-29T01:23:45 ET")
datetime_zoned = toZonedDateTime(datetime, timeZone("MT"))

hour = hourOfDay(datetime, timeZone("ET"), false)
hour_zoned = hourOfDay(datetime_zoned, false)

println hour
println hour_zoned