Current Timestamp in SQL

Current Unix Time
Advertisement

Current Timestamp in SQL

Getting the current timestamp in SQL is needed for auditing (recording when records were created or modified), filtering (finding records within a time range relative to now), scheduling (checking if something has expired), and logging (timestamping events). The exact function name and behavior differs across database systems, but the concept is universal.

A key consideration when working with SQL timestamps is timezone handling. Some databases (like PostgreSQL with timestamptz) store timestamps in UTC and convert to the session timezone for display. Others (like MySQL with DATETIME) store the literal datetime without timezone information. Always be explicit about which timezone you're working in, especially in applications with users in multiple countries.

Current timestamp functions by database

MySQL / MariaDB:
NOW() — DATETIME, local timezone
CURRENT_TIMESTAMP — same as NOW()
UTC_TIMESTAMP() — DATETIME in UTC
UNIX_TIMESTAMP() — INT, seconds since epoch

PostgreSQL:
NOW() — TIMESTAMPTZ, transaction start
CURRENT_TIMESTAMP — same as NOW()
CLOCK_TIMESTAMP() — TIMESTAMPTZ, actual current time
EXTRACT(EPOCH FROM NOW()) — FLOAT, Unix seconds

SQL Server:
GETDATE() — DATETIME, local
GETUTCDATE() — DATETIME, UTC
SYSDATETIMEOFFSET() — DATETIMEOFFSET with timezone
SYSUTCDATETIME() — DATETIME2 in UTC

SQLite:
datetime('now') — TEXT, UTC
strftime('%s','now') — TEXT, Unix seconds

Oracle:
SYSDATE — DATE (with time), local
SYSTIMESTAMP — TIMESTAMP WITH TIME ZONE

Advertisement
// Epoch → Human-readable date

Auto-detects seconds (10 digits), milliseconds (13), microseconds (16), nanoseconds (19)

Invalid timestamp. Please enter a numeric Unix timestamp.
// Date → Epoch timestamp
Please check the values — year (1970–9999), month (1–12), day (1–31), hour (0–23), min/sec (0–59).

Or paste a date string:

Could not parse that date string.
Advertisement

← Back to all tools

Copied!