SQL current UTC timestamp
The current instant expressed in UTC: the timestamp shape to persist for events, logs and any cross-zone comparison.
- Categoria
- Dates & times
- Returns
timestamp- In this category
- 114 of 121
Sintaxe
UTC_TIMESTAMP()
SYSUTCDATETIME()
datetime('now')
Each block is a separate form. The support table and the examples show which engine takes which.
Suporte a mecanismos
| Motor | Support | Notas |
|---|---|---|
| SQL Server | Sim | SYSUTCDATETIME() / GETUTCDATE() |
| PostgreSQL | Sim | now() AT TIME ZONE 'UTC' |
| MySQL | Sim | UTC_TIMESTAMP() |
| SQLite | Sim | strftime('%Y-%m-%d %H:%M:%S', 'now') |
| Oracle | Sim | SYS_EXTRACT_UTC(SYSTIMESTAMP) |
Exemplos
MySQL
SELECT UTC_TIMESTAMP(), NOW(); -- differ by session offset
SQLite
SELECT strftime('%Y-%m-%dT%H:%M:%SZ', 'now');
PostgreSQL
SELECT now() AT TIME ZONE 'UTC';
Bom saber
- SQLite's 'now' is UTC natively; the localtime modifier is the opt-in. Every other engine's local default needs the UTC spelling above.
- Oracle's SYSDATE and SYSTIMESTAMP are the *database server's* zone, not the session's; UTC conversion is SYS_EXTRACT_UTC(SYSTIMESTAMP), and neither touches session TIME_ZONE.
- MySQL's UTC_TIMESTAMP and NOW() differ by the session offset; mixing them in one table is how people get rows dated 2 hours in the future.
Questions about UTC_TIMESTAMP
Is UTC 'now' affected by DST?
Never. UTC has no offsets or transitions, which is precisely why it is the storage zone for event times.
Why is my UTC timestamp still wrong?
Usually the data was built from a local clock with a hardcoded offset. Compute UTC inside the database with the functions above instead of string surgery in app code.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
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.