Extract hours and minutes from a timestamp in BigQuery
How to pull the hour and minute out of a BigQuery TIMESTAMP with EXTRACT, FORMAT_TIMESTAMP or TIME, and which result type suits reporting, filtering or display.
BigQuery offers several ways to get the hour and minute from a TIMESTAMP. They return different data types. Which one fits depends on whether you need numbers for grouping and arithmetic, a readable clock string for display, or a time value you can still compare and sort. This review covers each option, what it changes in your data, and where it can mislead you.
Short recommendation
For grouping, filtering or calculations, use EXTRACT(HOUR FROM ...) and EXTRACT(MINUTE FROM ...). Each returns an INT64. For a label such as 14:07 in a report or export, use FORMAT_TIMESTAMP with a format string such as '%H:%M'. If you want a value that keeps time-of-day semantics and still sorts correctly, convert with TIME(...).
Time zones are the main tradeoff. BigQuery stores a TIMESTAMP as an absolute point in time and evaluates these functions in UTC unless you pass a time zone. An hour extracted without a time zone is the UTC hour, which may not be the local hour your readers expect.
Keep the full timestamp as plain, unformatted output when the exact moment matters. Examples include audit trails, joins across systems, and data that other tools will parse again. Extracting hours and minutes drops the date, the seconds and the offset.
Option 1: EXTRACT for numeric hours and minutes
EXTRACT returns a single date or time part as an integer. HOUR uses a 24-hour clock, from 0 to 23. MINUTE runs from 0 to 59. You can pass an optional time zone with AT TIME ZONE.
SELECT
EXTRACT(HOUR FROM ts) AS hour_utc,
EXTRACT(MINUTE FROM ts) AS minute_utc,
EXTRACT(HOUR FROM ts AT TIME ZONE 'America/New_York') AS hour_ny
FROM (
SELECT TIMESTAMP '2024-03-15 14:07:30+00' AS ts
);
For this input, hour_utc is 14 and minute_utc is 7. New York was on daylight saving time, four hours behind UTC, on that date, so hour_ny is 10. The minute is returned as 7, not 07. Integers carry no leading zeros.
This is the best fit for questions such as "how many events happened in each hour". You can GROUP BY the extracted hour directly. You can also compute minutes since midnight as EXTRACT(HOUR FROM ts) * 60 + EXTRACT(MINUTE FROM ts), which works for range filters and bucketing.
Option 2: FORMAT_TIMESTAMP for a readable clock string
FORMAT_TIMESTAMP returns a STRING built from format elements. %H is the zero-padded 24-hour hour, %M is the zero-padded minute, %I is the 12-hour hour, and %p is the AM/PM marker. The optional third argument sets the time zone.
SELECT
FORMAT_TIMESTAMP('%H:%M', ts) AS hh_mm_utc,
FORMAT_TIMESTAMP('%I:%M %p', ts, 'America/New_York') AS clock_ny
FROM (
SELECT TIMESTAMP '2024-03-15 14:07:30+00' AS ts
);
Here hh_mm_utc is '14:07' and clock_ny is '10:07 AM'. Strings read well in dashboards and CSV exports. However, they are text. Sorting compares characters, which works for zero-padded 24-hour strings but not for 12-hour strings with AM/PM. Arithmetic also needs a conversion back to a number or time first.
Option 3: TIME for a time-of-day value
TIME(ts) converts a TIMESTAMP to a TIME value, and it also accepts an optional time zone argument. The result keeps hours, minutes, seconds and fractional seconds, but drops the date. To keep only hours and minutes as a TIME, truncate it. To display it, format it.
SELECT
TIME(ts, 'America/New_York') AS local_time,
TIME_TRUNC(TIME(ts, 'America/New_York'), MINUTE) AS local_hh_mm,
FORMAT_TIME('%H:%M', TIME(ts, 'America/New_York')) AS local_label
FROM (
SELECT TIMESTAMP '2024-03-15 14:07:30+00' AS ts
);
Use this option when you want to compare times of day, such as events after 09:30 local time, without manual minute arithmetic. If you need a timestamp rounded to the minute rather than a bare time of day, TIMESTAMP_TRUNC(ts, MINUTE) keeps the date and the absolute moment.
What each approach actually changes
None of these functions rearranges characters or changes how text looks on screen. Each one derives a new value from the stored timestamp, and the original column stays unchanged unless you overwrite it. The real changes are the following:
| Approach | Result type | What is kept | What is lost |
| EXTRACT(HOUR / MINUTE) | INT64, one part per call | One numeric part | Date, other parts, offset, leading zeros |
| FORMAT_TIMESTAMP('%H:%M') | STRING | A human-readable clock label | Date, seconds, offset, native time comparison |
| TIME(ts) / TIME_TRUNC | TIME | Time of day, comparable and sortable | Date and offset |
| TIMESTAMP_TRUNC(ts, MINUTE) | TIMESTAMP | Date and absolute moment | Seconds and smaller units |
Column types matter too. On a DATETIME or TIME column, EXTRACT works the same way but accepts no time zone. These types do not represent an absolute moment, so BigQuery cannot convert them. If your times are stored as strings, parse them first with PARSE_TIMESTAMP or PARSE_DATETIME. Otherwise EXTRACT will not accept them.
Will the result stay usable after export or sharing?
- Time zone context does not travel with the value. A shared column labeled only 'hour' invites misreading, so name it or document it, for example hour_utc or hour_new_york.
- Integer minutes lose their leading zero. Rebuilding a label by joining two integers gives results like 10:7. Use FORMAT_TIMESTAMP or FORMAT_TIME when people will read the output.
- Spreadsheet and BI tools may reinterpret a string such as 14:07 as a time or as text, depending on the tool and its settings. Check this in the destination you actually use rather than assuming it.
- Daylight saving transitions can make a local hour repeat or disappear on certain dates. Counts by local hour on those days are not directly comparable to other days.
- Dropping the date is irreversible in the derived column. Keep the original timestamp alongside it if anyone may need to trace or rejoin rows.
Choosing between them
- Counting or grouping by hour: EXTRACT(HOUR FROM ts AT TIME ZONE ...)
- Filtering by time of day: TIME(ts, time_zone) compared against a TIME literal
- Displaying a clock label: FORMAT_TIMESTAMP('%H:%M', ts, time_zone)
- Rounding while keeping the exact moment: TIMESTAMP_TRUNC(ts, MINUTE)
- Passing data to another system that will parse it: the original TIMESTAMP, unformatted
Gaps in this review
No project-specific evidence was supplied, so this review contains no benchmarks, cost figures or test results from a live dataset. The function behavior and example outputs come from documented GoogleSQL semantics and the stated literal inputs. Run the snippets in your own project to confirm the results, and check how your dashboard, spreadsheet or export target treats the output types before relying on them.