CURRENT_TIME

Return the current time-of-day with time zone information.

Category: datetimeReturns: TIME WITH TIME ZONEDialect: PostgreSql

Syntax

CURRENT_TIME

Description

## Overview Returns the current time-of-day (hours, minutes, seconds, fractional seconds) along with the session time zone offset. Use CURRENT_TIME when the time-of-day matters but the calendar date does not, for example routing decisions based on business hours or shift schedules. The value is fixed at the start of the current transaction and remains stable for the duration of that transaction. Use CLOCK_TIMESTAMP if you need a value that advances during statement execution. ## Behavior - Returns a TIME WITH TIME ZONE value. - Never returns NULL. - Stable within a transaction; repeated calls return the same value. - Spelled as a bare keyword (no parentheses), matching the SQL standard. - Comparable directly to TIME literals and other TIME values. Comparison against TIME WITHOUT TIME ZONE values performs an implicit conversion using the session time zone. ## Timezone handling - The time zone component reflects the session time zone at transaction start. - When comparing CURRENT_TIME against a TIME WITHOUT TIME ZONE, the comparison uses the session time zone, so two sessions in different zones can see different ordering near zone boundaries. - Prefer LOCALTIME when you want a naive (zone-less) time that does not participate in zone arithmetic. ## Compatibility - Defined in the SQL standard (ANSI/ISO SQL:2016). An optional precision argument (CURRENT_TIME(p)) for sub-second precision is accepted in some dialects; when omitted, full available precision is returned.

Examples

-- Current time-of-day with time zone
SELECT CURRENT_TIME;
-- Extract the hour component from the current time
SELECT EXTRACT(HOUR FROM CURRENT_TIME) AS current_hour;
-- Tag rows as inside or outside business hours
SELECT user_id,
       CASE WHEN CURRENT_TIME BETWEEN TIME '09:00:00' AND TIME '17:00:00'
            THEN 'business_hours' ELSE 'after_hours' END AS activity_window
FROM analytics.events.user_activity;
-- Compare CURRENT_TIME (with tz) against LOCALTIME (without tz)
SELECT CURRENT_TIME AS tz_time, LOCALTIME AS local_time;
-- Count requests bucketed by the current hour at query time
SELECT COUNT(*) AS requests
FROM telemetry.web.requests
WHERE EXTRACT(HOUR FROM ingest_time) = EXTRACT(HOUR FROM CURRENT_TIME);

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →