TIMESTAMP is a core SQL data type that records an absolute point in time to the second or sub-second. Unlike DATE (date only) and TIME (time only), TIMESTAMP keeps both components in a single field, making it ideal for event logging, audit trails, and temporal analytics.Precision - Most dialects let you specify fractional‐seconds precision in parentheses, for example TIMESTAMP(3) for millisecond resolution. The valid range is typically 0-6 digits, where 6 equals microseconds.Time zone - Standard SQL defines TIMESTAMP WITHOUT TIME ZONE and TIMESTAMP WITH TIME ZONE. The latter normalizes values to UTC while remembering the original offset, ensuring global consistency. Some engines (MySQL, SQLite) ignore the WITH TIME ZONE variant, while PostgreSQL treats TIMESTAMP as WITHOUT TIME ZONE unless explicitly stated.Defaults and auto-update - CURRENT_TIMESTAMP (or NOW()) can be assigned as a default to auto-populate the current clock time at insert. In MySQL, you can also add ON UPDATE CURRENT_TIMESTAMP for automatic touch-timestamps.Storage - Internally, vendors store TIMESTAMP as either an 8-byte integer (Unix epoch microseconds) or a composite structure. Range usually spans 4713 BC to 294276 AD (PostgreSQL) or 1970-2038 (older MySQL when using 4-byte representation).Caveats - Be explicit about time zones. Mixing WITH and WITHOUT TIME ZONE leads to silent conversions. Fractional seconds above the engine limit round or raise errors. Always index high-write TIMESTAMP columns used in WHERE clauses to avoid slow scans.
fractional_seconds_precision
(integer) - number of digits after the decimal point (0-6)WITH TIME ZONE
(flag) - stores offset information and converts to UTC internallyDEFAULT CURRENT_TIMESTAMP
(expression) - auto-assigns the current date-time at insertDATE, TIME, DATETIME, CURRENT_TIMESTAMP, NOW(), INTERVAL, TIME ZONE
SQL-92
TIMESTAMP follows the SQL standard and can be time-zone aware, whereas DATETIME is proprietary and usually lacks automatic zone conversion. Check your DBMS docs before choosing.
Define created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP and updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP (MySQL) or use a trigger in PostgreSQL/Oracle.
You are using TIMESTAMP WITH TIME ZONE. The database converts the stored UTC time to your session's zone, so apparent values move when the offset changes.
Yes. Adding an index on frequently filtered TIMESTAMP columns (e.g., created_at) speeds up range queries and ORDER BY operations.