Extract clock time, hours and minutes from a timestamp in Teradata
How to pull the hour, minute or clock time out of a Teradata timestamp with EXTRACT, CAST and TO_CHAR, and how to pick a result type that stays usable downstream.
Teradata gives you several ways to get the hour, the minutes or the full clock time out of a TIMESTAMP value. They differ less in the number they produce than in the type of result they return. Some return a typed TIME value, some return integers, and some return a character string. That choice decides whether the result still sorts, compares and exports correctly once it leaves your query. This review covers what each approach changes and when each one is the right fit.
Short recommendation
Use EXTRACT when you need a numeric hour or minute for grouping, filtering or arithmetic. Use CAST to TIME when you need the time of day as a value you can still compare and sort. Convert to a formatted string such as HH:MI only at the final presentation step. A string is easy to read, but it loses date-time semantics, and its exact appearance depends on the format you choose.
In this context, "plain text" means a character string. A string is the better choice when the destination is a report, a CSV file or a label that people will read and that no later step will calculate with. It is the wrong choice when another query, join or tool needs to treat the value as a time.
What each approach actually changes
None of these approaches alters the stored timestamp. Each one derives a new value in the query result. The useful distinction is between a change in data type, which affects how downstream systems handle the value, and a change in display format, which may only affect how one client renders it.
Hour or minute as a number: EXTRACT
EXTRACT is the ANSI-standard way to pull a single field from a date-time value. It works on TIMESTAMP columns and on TIME columns, so extracting minutes from a TIME value uses the same syntax.
SELECT
EXTRACT(HOUR FROM event_ts) AS event_hour,
EXTRACT(MINUTE FROM event_ts) AS event_minute,
EXTRACT(SECOND FROM event_ts) AS event_second
FROM sales_events;
Hour and minute come back as integers, and an integer carries no leading zero. A time of 07:05 therefore yields 7 and 5, not "07" and "05". Seconds behave differently. For timestamps with fractional-second precision, the extracted second can include a fractional part, so check the returned type before you treat it as a whole number. The column and table names in these snippets are placeholders, and the snippets were not executed for this article.
Clock time as a TIME value: CAST
Casting a timestamp to TIME discards the date and keeps the time of day as a typed value. The result still compares and sorts as a time. Use the precision in parentheses to decide whether fractional seconds survive.
SELECT
CAST(event_ts AS TIME(0)) AS event_time -- drops fractional seconds
FROM sales_events;
Hours and minutes as text: TO_CHAR or FORMAT plus CAST
To get an HH:MM string, format the value and convert it to a character type. TO_CHAR is available in current Teradata releases. Older code often uses the Teradata FORMAT phrase instead, where MI stands for minutes.
SELECT
TO_CHAR(event_ts, 'HH24:MI') AS hhmi_tochar,
CAST(CAST(event_ts AS FORMAT 'HH:MI') AS CHAR(5)) AS hhmi_format
FROM sales_events;
The inner FORMAT on its own is a display instruction, not a type change. Wrapping it in CAST to CHAR is what turns the result into a stored string. Without that outer cast, the formatted look may appear in one tool and disappear in another (see the next section).
Minutes since midnight
If you need the clock time as a single comparable number, for example to build time buckets, combine the extracted fields.
SELECT
EXTRACT(HOUR FROM event_ts) * 60 + EXTRACT(MINUTE FROM event_ts) AS minutes_after_midnight
FROM sales_events;
| Goal | Approach | Result type | Main tradeoff |
| Numeric hour or minute | EXTRACT(HOUR / MINUTE FROM ts) | Integer | No leading zeros; you must rebuild it for display |
| Time of day, still comparable | CAST(ts AS TIME(n)) | TIME | Display depends on the client |
| Readable HH:MM label | TO_CHAR(ts, 'HH24:MI') or FORMAT plus CAST to CHAR | Character | Loses time semantics; sorts correctly only when zero-padded in 24-hour form |
| Single number for bucketing | Hour * 60 + minute | Integer | Not human-readable without conversion |
Will the result stay readable and usable after export or sharing?
The FORMAT phrase is a common source of surprise. BTEQ in its default field mode applies the FORMAT phrase when it prints results. Clients that connect through ODBC or JDBC typically receive the underlying typed value and apply their own formatting. A query that shows 07:30 in one tool can therefore show a full time, or a different layout, in another. If the exact text matters, convert it to a character type explicitly rather than relying on FORMAT alone. Behavior in a specific client should be confirmed in that client, because one correct rendering does not prove the others match.
Building HH:MM by concatenating extracted integers has a related pitfall. When Teradata implicitly converts a number to text, it can apply the type's default display format, which may add leading spaces and does not add leading zeros. If you take this route, set the width explicitly, for example by formatting each part as two digits before concatenating. Test the output on your system, because the default format can vary with column definitions and session settings.
- Choose a string when the value goes straight to people: reports, exported files, dashboard labels.
- Keep TIME or integers when the value feeds joins, filters, sorting or later calculations.
- Use 24-hour, zero-padded text (HH24:MI) when you must sort or compare strings, because 12-hour text without padding does not sort chronologically.
- Keep a typed column next to the formatted one when the same output serves both people and downstream processing.
Accessibility and search effects depend on the destination tool, not on Teradata. No documentation or tests specific to particular screen readers or search systems were available for this review. A conventional HH:MM string is the most widely understood written form of a clock time. Confirm how your destination presents it if that matters.
Time zones and other gaps to check
For TIMESTAMP WITH TIME ZONE columns, EXTRACT also supports TIMEZONE_HOUR and TIMEZONE_MINUTE for reading the offset. Whether the extracted hour reflects the stored offset or the session time zone depends on the data type and on session settings. Check that against the documentation for your release before you rely on hour-of-day results across regions. Function availability can also differ between releases, so TO_CHAR in particular is worth confirming on older systems. This review found no release-specific evidence, performance measurements or test results, and none are claimed here.