SQL LOCALTIMESTAMP function
Returns the current date and time as a plain timestamp, without any time-zone information, unlike CURRENT_TIMESTAMP on zone-aware engines.
- 카테고리
- Dates & times
- Returns
timestamp- In this category
- 17 of 121
구문
LOCALTIMESTAMP
LOCALTIMESTAMP(p)
NOW() -- MySQL synonym
Each block is a separate form. The support table and the examples show which engine takes which.
엔진 지원
| 엔진 | Support | 메모 |
|---|---|---|
| SQL Server | Different name or syntax | GETDATE(); no LOCALTIMESTAMP keyword |
| PostgreSQL | 예 | Supported under this name. |
| MySQL | 예 | Supported under this name. |
| SQLite | Different name or syntax | no keyword; datetime('now', 'localtime') |
| Oracle | 예 | Supported under this name. |
예시
PostgreSQL
SELECT LOCALTIMESTAMP(3) AS loaded_at;
MySQL
SELECT LOCALTIMESTAMP AS loaded_at;
Oracle
SELECT LOCALTIMESTAMP FROM dual;
알아 두면 좋은 정보
- On PostgreSQL the difference is real: CURRENT_TIMESTAMP is timestamptz, LOCALTIMESTAMP is timestamp; storing the wrong one bakes the session zone into the data.
- MySQL treats CURRENT_TIMESTAMP, NOW() and LOCALTIMESTAMP as exact synonyms; all three return the session time_zone's wall clock.
- LOCALTIMESTAMP is the transaction start time on PostgreSQL; clock_timestamp() is the moving wall clock.
Questions about LOCALTIMESTAMP
When should I use LOCALTIMESTAMP instead of CURRENT_TIMESTAMP?
Only when you genuinely want zone-less wall time. For event timestamps, zone-aware CURRENT_TIMESTAMP (or UTC) survives time-zone changes better.
Is LOCALTIMESTAMP available on SQL Server?
No keyword. GETDATE() or SYSDATETIME() return the server's local wall time as a zone-less value, which is the same idea (SQL Server has no per-session zone).
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.