Extract Time from a Timestamp in Snowflake

How to pull the time of day out of a Snowflake timestamp, what each method changes, and when a TIME value, a formatted string or a number fits best.

Getting the clock time out of a Snowflake timestamp sounds like a single step, but the method you choose changes the result. You can get a typed TIME value, a formatted text string or a single numeric component such as the hour. Each one behaves differently when you sort it, compare it, export it or paste it somewhere else. This review explains what each approach changes, when it suits your purpose and where the result can lose meaning. It draws on Snowflake's documented SQL behavior. No query results were measured for this article, so check the details against current Snowflake documentation and your own account settings before you rely on them.

Short answer: which method suits which use

If the time of day will feed further SQL, such as filters, joins, sorting or time arithmetic, cast the timestamp to the TIME data type. If you need a fixed, human-readable label for a report, export or message, format it as text with TO_CHAR. If you only care about one component, such as grouping events by hour, extract that component as a number. The deciding tradeoff is type versus appearance. A TIME value stays comparable and sortable, but how it displays depends on session settings. A formatted string looks the same everywhere, but it is only text, so later comparisons and arithmetic depend on the exact format you picked.

Goal | Suggested approach | Result type | Main caveat
Filter, sort or compare by time of day | ts::TIME, CAST(ts AS TIME) or TO_TIME(ts) | TIME | Display follows TIME_OUTPUT_FORMAT; the date is discarded
Fixed label for reports or exports | TO_CHAR(ts, 'HH24:MI:SS') | VARCHAR | Text only; 12-hour formats do not sort chronologically
Group or count by a single component | HOUR(ts), MINUTE(ts), EXTRACT(HOUR FROM ts) | Number | Loses all other parts of the time
Keep the full timestamp but drop finer detail | DATE_TRUNC('HOUR', ts) | Timestamp | Not a time-of-day value; the date is kept

What each method actually changes

Casting to TIME changes the stored data type. The date portion is discarded, and the time of day is kept, including fractional seconds up to the precision of the target type. Snowflake documents TIME, TO_TIME and the :: cast shorthand as ways to perform this conversion. The new value is a real time-of-day value, so it can be compared with other TIME values and used in time functions.

Formatting with TO_CHAR (also available as TO_VARCHAR) does not produce a time value at all. It produces characters arranged according to a format model, such as HH24 for a 24-hour hour, HH12 with AM or PM for a 12-hour clock, MI for minutes, SS for seconds and FF for fractional seconds. The stored result is exactly the text you asked for, which makes it predictable to display but turns it into a string as far as the database is concerned.

Component extraction with HOUR, MINUTE, SECOND, EXTRACT or DATE_PART returns a number for one field. This is useful for grouping, but it is a reduction, not a conversion. Ten past two and fifty past two both become 14 when you extract the hour.

Storage and presentation are separate even for a typed TIME value. Snowflake displays TIME values using the TIME_OUTPUT_FORMAT parameter, which commonly defaults to hours, minutes and seconds. A value can therefore hold fractional seconds that the default display does not show. If the output looks less precise than you expected, check the display format before you assume the data was truncated.

-- Illustrative query; column and table names are placeholders
SELECT
  created_at,
  created_at::TIME                   AS time_value,   -- TIME type
  TO_CHAR(created_at, 'HH24:MI:SS')  AS time_24h,     -- text
  TO_CHAR(created_at, 'HH12:MI AM')  AS time_12h,     -- text
  HOUR(created_at)                   AS hour_number   -- number
FROM orders;

Here is an illustrative example of the documented behavior, not a measured run. For an input of 2024-03-15 14:07:32.123, the cast keeps 14:07:32.123 as a TIME value, although the default display may show only 14:07:32. The 24-hour format returns the text 14:07:32, the 12-hour format returns text like 02:07 PM, and the hour extraction returns 14.

Time zones: the change that is easiest to miss

Snowflake has three timestamp variants, and the extracted clock time depends on which one you start from. TIMESTAMP_NTZ has no time zone, so the time you extract is the wall-clock time exactly as stored. TIMESTAMP_LTZ is interpreted in the session's TIME_ZONE setting, so the same stored instant can yield different clock times for users or jobs with different session settings. TIMESTAMP_TZ carries an offset. Extracting the time gives the wall-clock time in that offset, and the offset itself is dropped from the TIME result.

This matters for meaning. A TIME value of 09:00 says nothing about which zone it refers to. If readers in different regions will see the result, either convert to a known zone first (for example with CONVERT_TIMEZONE) or keep the zone in the output label. Otherwise the value is technically correct but easy to misread.

When the timestamp is stored as text

Some tables hold timestamps in VARCHAR columns, often from file loads. In that case, parse the text before you extract anything. TO_TIMESTAMP with an explicit format model parses the string, and TRY_TO_TIMESTAMP or TRY_TO_TIME return NULL instead of raising an error when a row does not match the format. Pulling the time out with string functions or a regular expression, such as REGEXP_SUBSTR or SUBSTR, is a plain-text extraction. It is reasonable only when every row follows one rigid layout and you need the characters, not a comparable value. It cannot catch an invalid hour or minute, and it cannot apply time-zone logic.

-- Illustrative: parse text first, then extract the time
SELECT
  TRY_TO_TIMESTAMP(raw_ts, 'YYYY-MM-DD HH24:MI:SS')::TIME AS time_value
FROM staging_events;

Will the result stay readable and usable after copying or sharing?

A TIME value that leaves Snowflake as part of a query export, a clipboard copy or a BI extract usually travels as text in whatever display format applied at the time. The receiving tool then decides how to interpret that text. Spreadsheets and BI tools may reinterpret time-like strings, change their display or attach a date. This article did not test how any specific destination handles them, so check your actual target before you depend on a particular result.

  • Sorting: zero-padded 24-hour strings such as 09:05:00 sort in clock order, but 12-hour strings with AM or PM do not sort chronologically as text.
  • Comparison: comparing formatted strings works only if both sides use the identical format; TIME values compare correctly regardless of display.
  • Midnight: TIME has no date, so differences across midnight (for example 23:30 to 00:15) need the original timestamps, not the extracted times.
  • Precision: fractional seconds may be stored but hidden by the display format, or cut off by a format model that lacks FF.
  • Zone ambiguity: an exported time carries no zone unless you add one to the label or column name.

Accessibility depends on the output format. Standard clock notation in plain digits and colons is ordinary text, so screen readers and search treat it like any other text. However, how a particular assistive technology announces formats such as 14:07:32 versus 2:07 PM was not tested here and may vary. If a shared report is meant for a general audience, a 12-hour format with AM or PM plus an explicit time zone is often clearer to read. For anything that will be reprocessed, keep the 24-hour format or the typed TIME value.

When plain text is the better choice

Choose a formatted string when the output is final. Examples include a label in an email, a column in a static CSV handed to people rather than systems, or a display field where the exact appearance matters more than computation. Choose a TIME value when anything downstream will filter, sort, join or calculate. When you need both, return both columns, so readers get a stable label and systems get a typed value.

Gaps in this review

No query results, performance measurements or destination-specific tests were available for this article. The behavior described is based on Snowflake's documented functions and data types. Default parameter values and edge cases can change between releases and can be overridden at account, user or session level. Before you adopt a pattern in production, confirm it in your own environment, especially time-zone handling for TIMESTAMP_LTZ and how your export target treats time strings.