SQL Keywords

SQL UTC_TIMESTAMP

What is UTC_TIMESTAMP in SQL?

Returns the current Coordinated Universal Time (UTC) as a DATETIME or string value.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL UTC_TIMESTAMP:

SQL UTC_TIMESTAMP Full Explanation

UTC_TIMESTAMP is a MySQL and MariaDB built-in date and time function that produces the current UTC date and time. It behaves like NOW(), except it is timezone-agnostic and always returns the value in UTC rather than the server or session time zone. The function can be written with or without parentheses. If called in a string context it yields a string such as '2024-05-11 14:32:18'. In numeric context it returns a number like 20240511143218.000000. Fractional seconds precision matches the global or session setting of `time_precision` (0-6). When used in DDL as a default or on-update expression for TIMESTAMP or DATETIME columns, it guarantees that all stored values represent UTC, simplifying cross-region replication, logging, and analytics.

SQL UTC_TIMESTAMP Syntax

UTC_TIMESTAMP;
-- or
UTC_TIMESTAMP();

SQL UTC_TIMESTAMP Parameters

Example Queries Using SQL UTC_TIMESTAMP

-- Get the current UTC date and time
SELECT UTC_TIMESTAMP();

-- Compare local time (NOW()) with UTC
SELECT NOW() AS local_time, UTC_TIMESTAMP() AS utc_time;

-- Use as a default value in table definition
CREATE TABLE events (
  id INT PRIMARY KEY,
  occurred_at DATETIME DEFAULT UTC_TIMESTAMP
);

-- Schedule a future UTC moment
SELECT UTC_TIMESTAMP() + INTERVAL 1 DAY AS utc_tomorrow;

Expected Output Using SQL UTC_TIMESTAMP

  • Each query returns the current UTC date and time at execution in 'YYYY-MM-DD HH:MM:SS[
  • fraction]' format
  • In table definitions, new rows automatically store the UTC timestamp in occurred_at

Use Cases with SQL UTC_TIMESTAMP

  • Store timestamps independent of server location
  • Compare events recorded across multiple time zones
  • Populate audit columns such as created_at_utc or updated_at_utc
  • Drive time-based partitioning where all shards follow a single clock
  • Generate consistent log entries for distributed systems

Common Mistakes with SQL UTC_TIMESTAMP

  • Assuming returned value matches server local time; it is always UTC
  • Forgetting to add parentheses in some client libraries
  • Using UTC_TIMESTAMP for default values but casting column to TIMESTAMP without proper timezone handling when read by applications
  • Expecting it to work in PostgreSQL or SQL Server, where the function name is different

Related Topics

First Introduced In

MySQL 4.1

Frequently Asked Questions

What is the return type of UTC_TIMESTAMP?

It returns a DATETIME value in string context and a numeric value in numeric context, both representing the current UTC date and time.

Does UTC_TIMESTAMP consider the server's time zone settings?

No. It ignores the server's time zone and always provides Coordinated Universal Time.

How do I store UTC timestamps automatically?

Define your DATETIME or TIMESTAMP column with `DEFAULT UTC_TIMESTAMP` (and `ON UPDATE UTC_TIMESTAMP` if needed) so MySQL fills the column without manual input.

Is UTC_TIMESTAMP available in PostgreSQL or SQL Server?

Not under that name. Use `now() AT TIME ZONE 'UTC'` in PostgreSQL and `GETUTCDATE()` in SQL Server.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!