TIMEOFDAY

Return the current wall-clock date and time as a formatted text string.

Category: datetimeReturns: STRINGDialect: PostgreSql

Syntax

TIMEOFDAY()

Description

## Overview Returns the current wall-clock date and time as a text (VARCHAR) string formatted in a human-readable style with day-of-week, month, day, time, year, and zone. Semantically it mirrors CLOCK_TIMESTAMP (the value is re-read on every call) but the return type is text rather than TIMESTAMP. Use TIMEOFDAY for quick debug output or log annotations where a human-readable string is more convenient than a typed timestamp. For arithmetic, filtering, and storage prefer CLOCK_TIMESTAMP. ## Behavior - Returns a VARCHAR value. - Never returns NULL. - Not stable within a statement: successive calls can return different strings. - Reflects the session time zone in the formatted output (including zone abbreviation). - Requires the function-call parentheses. ## Timezone handling - The formatted string includes a zone abbreviation derived from the session time zone. - To obtain the same instant as a typed value, cast to TIMESTAMP WITH TIME ZONE or use CLOCK_TIMESTAMP directly. ## Compatibility - Extension beyond the SQL standard. Intended for legacy compatibility and debugging; most application code should use CLOCK_TIMESTAMP.

Examples

-- Current wall-clock date-time as text
SELECT TIMEOFDAY();
-- Compare with NOW (different return types)
SELECT TIMEOFDAY() AS text_ts, NOW() AS timestamp_ts;
-- Capture two successive readings in one statement
SELECT TIMEOFDAY() AS t1, pg_sleep(0.05), TIMEOFDAY() AS t2;
-- Write a human-readable checkpoint into a debug log
INSERT INTO security.audit.access_log (action, notes)
VALUES ('checkpoint', TIMEOFDAY());
-- Convert the text back to a timestamp when needed
SELECT TIMEOFDAY()::TIMESTAMP WITH TIME ZONE AS parsed_instant;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →