SQL SYSUTCDATETIME function
Returns the current instant in UTC directly, skipping the local-clock-minus-offset arithmetic where bugs breed.
- Returns
datetime2 / datetime / timestamp- In this category
- 112 of 121
語法
SYSUTCDATETIME()
GETUTCDATE()
UTC_TIMESTAMP
Each block is a separate form. The support table and the examples show which engine takes which.
引擎支援
| 引擎 | Support | 備註 |
|---|---|---|
| SQL Server | 是 | Supported under this name. |
| PostgreSQL | Different name or syntax | now() AT TIME ZONE 'UTC' or CURRENT_TIMESTAMP rendered in UTC |
| MySQL | 是 | UTC_TIMESTAMP() |
| SQLite | Different name or syntax | strftime('%Y-%m-%d %H:%M:%S', 'now'); 'now' is UTC |
| Oracle | Different name or syntax | SYS_EXTRACT_UTC(SYSTIMESTAMP) |
範例
SQL Server
SELECT SYSUTCDATETIME(), GETUTCDATE();
MySQL
SELECT UTC_TIMESTAMP(6);
Oracle
SELECT SYS_EXTRACT_UTC(SYSTIMESTAMP) FROM dual;
小知識
- UTC now is the timestamp to store: event ordering survives servers moved across zones, and DST never rewrites history. Local clocks belong at the edges of the system.
- GETUTCDATE returns datetime (1/300-second ticks) and SYSUTCDATETIME returns datetime2(7). Neither carries an offset; SYSDATETIMEOFFSET() is the call that does.
- SQLite's 'now' is already UTC; datetime('now', 'localtime') is the explicit local step, never the reverse.
Questions about SYSUTCDATETIME
Why prefer UTC columns over local time?
Local times repeat during DST fall-back and skip during spring-forward, so in Central European time '2026-03-29 02:30' does not exist and '2026-10-25 02:30' happens twice. UTC has no gaps or repeats.
What is the Oracle equivalent of SYSUTCDATETIME?
SYS_EXTRACT_UTC(SYSTIMESTAMP) for the instant; SYSTIMESTAMP AT TIME ZONE 'UTC' gives the same with zone-aware rendering.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
- Get the Unix timestamp of a date in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- Archive old rows to a history table Snippet
- Find rows expiring within N days in SQL Snippet
- Schema version table recipe Snippet
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.