DateTimeZone.ZoneHours
DateTimeZoneReturns the hour component of the UTC offset for a datetimezone value.
Syntax
DateTimeZone.ZoneHours(dateTimeZone as datetimezone) as numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTimeZone | datetimezone | Yes | A datetimezone value. |
Return Value
number — An integer representing the hours component of the UTC offset (e.g., -5 for UTC-5, 5 for UTC+5:30).
Remarks
DateTimeZone.ZoneHours returns the whole-hours component of the UTC offset for a datetimezone value. For a value with offset +05:30, this returns 5. For -08:00, it returns -8. For UTC (+00:00), it returns 0. To get the minutes component of the offset, use DateTimeZone.ZoneMinutes. Together, these two functions let you extract timezone metadata without fully decomposing the value via DateTimeZone.ToRecord.
A common use case is grouping or filtering datetimezone values by their source timezone — for example, separating events sourced from US Eastern (ZoneHours = -5) vs. UK (ZoneHours = 0) vs. India (ZoneHours = 5). Note that this only identifies the offset, not the named timezone (e.g., UTC-5 could be EST, CDT, or any other timezone with that offset).
DateTimeZone.ZoneHours is most useful when you need only the hours part of the offset quickly. For the complete offset (hours and minutes together), build it from both components: DateTimeZone.ZoneHours(x) * 60 + DateTimeZone.ZoneMinutes(x) gives total offset in minutes.
Examples
Example 1: Extract timezone hour offsets from a set of datetimezone values
#table(
type table [DTZ = datetimezone, ZoneHours = number],
{
{#datetimezone(2024, 3, 15, 8, 30, 0, -5, 0), DateTimeZone.ZoneHours(#datetimezone(2024, 3, 15, 8, 30, 0, -5, 0))},
{#datetimezone(2024, 3, 15, 14, 0, 0, 1, 0), DateTimeZone.ZoneHours(#datetimezone(2024, 3, 15, 14, 0, 0, 1, 0))},
{#datetimezone(2024, 3, 16, 9, 15, 0, 5, 30), DateTimeZone.ZoneHours(#datetimezone(2024, 3, 16, 9, 15, 0, 5, 30))},
{#datetimezone(2024, 3, 16, 17, 45, 0, 0, 0), DateTimeZone.ZoneHours(#datetimezone(2024, 3, 16, 17, 45, 0, 0, 0))}
}
)DTZ | ZoneHours | |
|---|---|---|
| 1 | 3/15/2024 1:30:00 PM | -5 |
| 2 | 3/15/2024 1:00:00 PM | 1 |
| 3 | 3/16/2024 3:45:00 AM | 5 |
| 4 | 3/16/2024 5:45:00 PM | 0 |
Example 2: Get the zone hours for a specific datetimezone
#table(
type table [DTZ = datetimezone, ZoneHours = number],
{{#datetimezone(2024, 3, 15, 14, 30, 0, 5, 30),
DateTimeZone.ZoneHours(#datetimezone(2024, 3, 15, 14, 30, 0, 5, 30))}}
)DTZ | ZoneHours | |
|---|---|---|
| 1 | 3/15/2024 9:00:00 AM | 5 |
Example 3: Build a total offset in minutes from ZoneHours and ZoneMinutes
#table(
type table [DTZ = datetimezone, OffsetMinutes = number],
{
{#datetimezone(2024, 3, 15, 8, 30, 0, -5, 0),
DateTimeZone.ZoneHours(#datetimezone(2024, 3, 15, 8, 30, 0, -5, 0)) * 60
+ DateTimeZone.ZoneMinutes(#datetimezone(2024, 3, 15, 8, 30, 0, -5, 0))},
{#datetimezone(2024, 3, 16, 9, 15, 0, 5, 30),
DateTimeZone.ZoneHours(#datetimezone(2024, 3, 16, 9, 15, 0, 5, 30)) * 60
+ DateTimeZone.ZoneMinutes(#datetimezone(2024, 3, 16, 9, 15, 0, 5, 30))}
}
)DTZ | OffsetMinutes | |
|---|---|---|
| 1 | 3/15/2024 1:30:00 PM | -300 |
| 2 | 3/16/2024 3:45:00 AM | 330 |