Extract clock time, hours and minutes from Oracle DATE and TIMESTAMP
How to pull the hour, minute or full clock time out of Oracle DATE and TIMESTAMP values, and when to use EXTRACT, TO_CHAR or the original datetime.
Oracle has no separate TIME data type. A DATE always carries a time of day to the second, and a TIMESTAMP adds fractional seconds and, in some variants, a time zone. Extracting the clock time means one of two things: returning a component such as the hour or minute as a number, or rendering the time portion as text. The right choice depends on whether the result will be calculated with, compared, or shown to a person. This review covers documented Oracle behavior. No version-specific tests were run for it, so confirm edge cases on your own database release.
Short recommendation
Use EXTRACT when you need the hour or minute as a number for arithmetic, grouping or numeric comparison. Use TO_CHAR when you need readable text such as 14:05 or 02:05 PM for a report, an export or a label. Keep the original DATE or TIMESTAMP column for storage, sorting across days and range filtering. Both EXTRACT and TO_CHAR discard the date, and TO_CHAR also discards the datetime type. The main tradeoff is that a formatted string is easy to read and copy but no longer behaves like a time. A plain text time is the better output only at the point where the data leaves the database for people or for systems that expect text.
What each approach changes
| Approach | Works directly on | Returns | Stored value changed? |
| EXTRACT(HOUR or MINUTE FROM ts) | TIMESTAMP types | NUMBER | No |
| EXTRACT(HOUR FROM CAST(d AS TIMESTAMP)) | DATE, after casting | NUMBER | No |
| TO_CHAR(d, 'HH24:MI:SS') | DATE and TIMESTAMP | VARCHAR2 text | No |
| d - TRUNC(d) | DATE | NUMBER, fraction of a day | No |
| TRUNC(d) | DATE | DATE set to midnight | No, it removes the time from the result only |
None of these functions modifies the stored column. They change only what the query returns. The difference that matters is the output type: a NUMBER from EXTRACT can be added and compared numerically, while a VARCHAR2 from TO_CHAR is text whose meaning depends on the format mask used to produce it.
Extracting the hour from a TIMESTAMP
EXTRACT accepts HOUR, MINUTE and SECOND when the source is a TIMESTAMP. SECOND includes any fractional part.
SELECT EXTRACT(HOUR FROM order_ts) AS hr,
EXTRACT(MINUTE FROM order_ts) AS mi,
EXTRACT(SECOND FROM order_ts) AS sec
FROM orders;
Time zones need care. When the source is TIMESTAMP WITH TIME ZONE, Oracle documents that EXTRACT returns the value in UTC, not in the zone stored with the value. SYSTIMESTAMP returns this type, so EXTRACT(HOUR FROM SYSTIMESTAMP) can differ from the hour shown on a local clock. To get the hour as it appears in the value's own zone, format it with TO_CHAR or cast it to a plain TIMESTAMP first.
SELECT EXTRACT(HOUR FROM SYSTIMESTAMP) AS hour_utc,
TO_NUMBER(TO_CHAR(SYSTIMESTAMP, 'HH24')) AS hour_as_shown,
EXTRACT(HOUR FROM CAST(SYSTIMESTAMP AS TIMESTAMP)) AS hour_cast
FROM dual;
Extracting hours and minutes from a DATE, including SYSDATE
For a DATE source, EXTRACT supports only YEAR, MONTH and DAY. Asking for HOUR or MINUTE from a DATE raises ORA-30076, invalid extract field for extract source. Because SYSDATE is a DATE, EXTRACT(HOUR FROM SYSDATE) fails for the same reason. Cast the value to TIMESTAMP first, or use TO_CHAR.
-- Numeric hour and minute from a DATE
SELECT EXTRACT(HOUR FROM CAST(SYSDATE AS TIMESTAMP)) AS hr,
EXTRACT(MINUTE FROM CAST(SYSDATE AS TIMESTAMP)) AS mi
FROM dual;
-- Same values via TO_CHAR, converted back to numbers
SELECT TO_NUMBER(TO_CHAR(SYSDATE, 'HH24')) AS hr,
TO_NUMBER(TO_CHAR(SYSDATE, 'MI')) AS mi
FROM dual;
Extracting the full time of day as text
TO_CHAR with a time-only format mask is the most direct way to get the clock time from a DATE or datetime value.
SELECT TO_CHAR(created_at, 'HH24:MI:SS') AS time_24h,
TO_CHAR(created_at, 'HH:MI AM') AS time_12h,
TO_CHAR(created_at, 'HH24:MI:SS.FF3') AS time_ms -- TIMESTAMP only
FROM events;
- MI means minutes. MM means month, and using it for minutes is a common error that produces plausible-looking but wrong output.
- HH and HH12 return a 12-hour value. Use HH24 for 0 to 23.
- The AM or PM element is filled in for the actual time, so 'HH:MI AM' still prints PM in the afternoon. Its wording follows NLS_DATE_LANGUAGE unless a language is passed as the third argument to TO_CHAR.
- The FM modifier removes leading zeros and padding, for example 9:05 instead of 09:05.
- FF fractional seconds apply to TIMESTAMP values. A DATE has no fractional seconds.
Time of day as a duration or number of minutes
Subtracting TRUNC(d) from a DATE yields the elapsed fraction of the day. Multiplying by 24 or 1440 converts it to hours or minutes, but fractions such as one third of a day cannot be represented exactly, so the product can land just below a whole number. Round it, or build the value from integer components instead. If you need an interval type, cast both sides to TIMESTAMP.
-- Minutes since midnight from integer components
SELECT EXTRACT(HOUR FROM CAST(d AS TIMESTAMP)) * 60
+ EXTRACT(MINUTE FROM CAST(d AS TIMESTAMP)) AS minutes_since_midnight
FROM t;
-- Fraction-of-day method, rounded
SELECT ROUND((d - TRUNC(d)) * 1440) AS minutes_since_midnight
FROM t;
-- Time of day as INTERVAL DAY TO SECOND
SELECT CAST(d AS TIMESTAMP) - CAST(TRUNC(d) AS TIMESTAMP) AS time_of_day
FROM t;
Why the time sometimes seems to be missing
If a query shows only a date such as 31-OCT-26, the time is usually still stored. A DATE is displayed according to the session's NLS_DATE_FORMAT, and common defaults omit the time portion. Apply an explicit TO_CHAR mask or change the session format before concluding that the time was lost.
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
Will the result stay readable and usable after copying or sharing?
Numeric results from EXTRACT copy as ordinary numbers but lose context: 14 does not say whether it is a local or UTC hour. Label columns accordingly. Text from TO_CHAR copies as plain characters with no hidden formatting, which suits reports and messages. Several usability limits still apply.
- Sorting: zero-padded 24-hour strings such as 09:05 and 14:30 sort correctly as text. 12-hour strings and FM-trimmed strings do not.
- Filtering: comparing TO_CHAR(col, 'HH24:MI') BETWEEN '09:00' AND '17:00' works with zero-padded 24-hour text, but wrapping the column in a function generally prevents an ordinary index on that column from being used. A function-based index on the same expression is the usual remedy.
- Locale: AM and PM markers follow language settings, so a shared 12-hour string may read differently to recipients who expect other conventions. 24-hour text avoids this.
- Time zone: once a TIMESTAMP WITH TIME ZONE is formatted as a bare clock time, the zone is gone unless you include it with a TZR or TZH:TZM element.
- Round-tripping: a text time cannot be compared with dates or used in date arithmetic without converting it back, so keep the source column when later calculation is likely.
Applications that receive exported text, such as spreadsheets, may reinterpret a value like 09:05 as their own time type and change its display or drop the leading zero. That behavior depends on the receiving software and its import settings and was not tested for this review. Likewise, how a screen reader announces 14:05 versus 2:05 PM depends on the assistive technology and its configuration. No test evidence was available, so where people will hear rather than see the value, adding a column label that states the clock convention and time zone is a low-risk precaution.
Choosing quickly
| Need | Use |
| Hour or minute as a number from TIMESTAMP | EXTRACT(HOUR or MINUTE FROM ts) |
| Hour or minute as a number from DATE or SYSDATE | EXTRACT on CAST(d AS TIMESTAMP), or TO_NUMBER(TO_CHAR(d, 'HH24')) |
| Local hour from SYSTIMESTAMP | TO_CHAR(SYSTIMESTAMP, 'HH24'), since EXTRACT returns UTC for zoned values |
| Readable clock time for display or export | TO_CHAR(d, 'HH24:MI:SS') or 'HH:MI AM' |
| Minutes since midnight | EXTRACT hour times 60 plus minute, or rounded fraction-of-day arithmetic |
| Sorting or filtering across days | The original DATE or TIMESTAMP column |
Gaps in this review
No subject-specific evidence, version notes or test results were supplied. The behavior above reflects Oracle's general documented rules for EXTRACT, TO_CHAR, CAST and DATE arithmetic. Claims about spreadsheets, other destinations and assistive technology are stated as unverified. Check results against your Oracle version, session NLS settings and session time zone before relying on them in production.