SQL SESSIONTIMEZONE function
Returns the time zone of the current session. On other engines it is a setting to read: SHOW timezone on PostgreSQL, @@session.time_zone on MySQL.
- Catégorie
- Dates & times
- Returns
text (zone name or offset)- In this category
- 62 of 121
Syntaxe
SESSIONTIMEZONE
DBTIMEZONE -- Oracle
SHOW timezone -- PostgreSQL
@@session.time_zone -- MySQL
Each block is a separate form. The support table and the examples show which engine takes which.
Prise en charge des moteurs
| Moteur | Support | Notes |
|---|---|---|
| SQL Server | Not built in | no session zone; CURRENT_TIMEZONE() (SQL Server 2022+) reports the server's |
| PostgreSQL | Different name or syntax | SHOW timezone; CURRENT_SETTING('timezone') |
| MySQL | Different name or syntax | @@session.time_zone, @@global.time_zone |
| SQLite | Not built in | no zones; UTC storage with a 'localtime' modifier |
| Oracle | Oui | Supported under this name. |
Exemples
Oracle
SELECT SESSIONTIMEZONE, DBTIMEZONE FROM dual;
PostgreSQL
SHOW timezone;
MySQL
SELECT @@session.time_zone, @@global.time_zone;
Bon à savoir
- Oracle has two zones and they can disagree: SESSIONTIMEZONE drives CURRENT_TIMESTAMP and LOCALTIMESTAMP, while DBTIMEZONE only sets how TIMESTAMP WITH LOCAL TIME ZONE columns are stored. SYSDATE and SYSTIMESTAMP follow neither; they use the server OS clock.
- Named zones like 'Europe/London' return NULL conversions on MySQL until the time-zone tables are loaded with mysql_tzinfo_to_sql.
- SQL Server has no per-session zone: the server's OS zone applies to everything, so zone logic lives in AT TIME ZONE calls instead.
Questions about SESSIONTIMEZONE
Why do two sessions see different CURRENT_TIMESTAMP values?
The instant is the same; the rendering follows each session's zone. SESSIONTIMEZONE (Oracle) or SHOW timezone (PostgreSQL) tells you which zone is at play.
What is the difference between DBTIMEZONE and SESSIONTIMEZONE?
DBTIMEZONE is the database's storage zone for TIMESTAMP WITH LOCAL TIME ZONE columns; SESSIONTIMEZONE is the connection's display 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: PostgreSQL, MySQL, 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.