SQL - CURRENT_TIMEZONE_ID() Function



The SQL CURRENT_TIMEZONE_ID() function is an in-built function in SQL that is used to retrieve the ID of the current time zone observed by a server or an instance.

The ID returned by the CURRENT_TIMEZONE_ID() function may vary on different database management systems. Whether it can be the name of the time zone or the abbrevation. For instance, in Oracle, this function might return 'America/New_York' for Eastern Time in the United States, while in IBM Db2, it might return 'EST5EDT' for the same time zone.

Note − In SQL, The timezone is always set to UTC and CURRENT_TIMEZONE_ID will return the id of the UTC time zone.

Syntax

Following is the syntax of the SQL CURRENT_TIMEZONE_ID() function −

CURRENT_TIMEZONE_ID()

Parameters

This function does not accept any parameters.

Example

The following example demonstrates the usage of the SQL CURRENT_TIMEZONE_ID() function in SQL −

SQL> SELECT CURRENT_TIMEZONE_ID() AS CURRENT_TIMEZONE_ID;

Output

When we execute the above query, the output is obtained as follows −

+----------------------+	
| CURRENT_TIMEZONE_ID  |
+----------------------+
| India Standard Time  |
+----------------------+

Example

We can retrieve all the time zone ids on the database server using the following query −

SQL> SELECT * FROM sys.time_zone_info;

Output

If we execute the above query, the result is produced as follows −

+-----------------------------------+--------------------+------------------+
| name                              | current_utc_offset | is_currently_dst | 
+-----------------------------------+--------------------+------------------+
| Dateline Standard Time            | -12:00             | 0                |              
| Dateline Standard Time            | -11:00             | 0                |
| UTC-11                            | -10:00             | 0                |
| Aleutian Standard Time            | -10:00             | 0                |
| Hawaiian Standard Time            | -09:30             | 0                |
| Marquesas Standard Time           | -09:00             | 0                |
| Alaskan Standard Time             | -09:00             | 0                |
| UTC-09                            | -08:00             | 0                |
| Pacific Standard Time (Mexico)    | -08:00             | 0                |
| UTC-08                            | -08:00             | 0                |
| Pacific Standard Time             | -07:00             | 0                |
| US Mountain Standard Time         | -07:00             | 0                |
| Mountain Standard Time (Mexico)   | -07:00             | 0                |
| Mountain Standard Time            | -07:00             | 0                |
| Yukon Standard Time               | -06:00             | 0                |
| Central America Standard Time     | -06:00             | 0                |
| Central Standard Time             | -05:00             | 0                |
| Easter Island Standard Time       | -06:00             | 1                |
| Central Standard Time (Mexico)    | -06:00             | 0                |
| Canada Central Standard Time      | -05:00             | 0                |
| SA Pacific Standard Time          | -05:00             | 0                |
| Eastern Standard Time (Mexico)    | -05:00             | 0                |
| Eastern Standard Time             | -05:00             | 0                |
| Haiti Standard Time               | -05:00             | 0                |
| Cuba Standard Time                | -05:00             | 0                |
| US Eastern Standard Time          | -05:00             | 0                |
| Turks And Caicos Standard Time    | -03:00             | 0                |
| Paraguay Standard Time            | -04:00             | 1                |
| Atlantic Standard Time            | -04:00             | 0                |
| Venezuela Standard Time           | -04:00             | 0                |
| Central Brazilian Standard Time   | -04:00             | 0                |
| SA Western Standard Time          | -03:00             | 0                |
| Pacific SA Standard Time          | -03:30             | 1                |
| Newfoundland Standard Time        | -03:00             | 0                |
| Tocantins Standard Time           | -03:00             | 0                |
| E. South America Standard Time    | -03:00             | 0                |
| SA Eastern Standard Time          | -03:00             | 0                |
| Argentina Standard Time           | -03:00             | 0                |
| Greenland Standard Time           | -03:00             | 0                |
| Montevideo Standard Time          | -03:00             | 0                |
| Magallanes Standard Time          | -03:00             | 0                |
| Saint Pierre Standard Time        | -03:00             | 0                |
| Bahia Standard Time               | -02:00             | 0                |
| UTC-02                            | -02:00             | 0                |
| Mid-Atlantic Standard Time        | -01:00             | 0                |
| Azores Standard Time              | -01:00             | 0                |
| Cape Verde Standard Time          | +00:00             | 0                |
| UTC                               | +00:00             | 0                |
| GMT Standard Time                 | +00:00             | 0                |
| Greenwich Standard Time           | +00:00             | 0                |
| Sao Tome Standard Time            | +01:00             | 0                |
| Morocco Standard Time             | +01:00             | 1                |
| W. Europe Standard Time           | +01:00             | 0                |
| Central Europe Standard Time      | +01:00             | 0                |
| Romance Standard Time             | +01:00             | 0                |
| Central European Standard Time    | +01:00             | 0                |
| W. Central Africa Standard Time   | +02:00             | 0                |
| GTB Standard Time                 | +02:00             | 0                |
| Middle East Standard Time         | +02:00             | 0                |
| Egypt Standard Time               | +02:00             | 0                |
| E. Europe Standard Time           | +02:00             | 0                |
| Syria Standard Time               | +02:00             | 0                |
| West Bank Standard Time           | +02:00             | 0                |
| South Africa Standard Time        | +02:00             | 0                |
| FLE Standard Time                 | +02:00             | 0                |
| Israel Standard Time              | +02:00             | 0                |
| South Sudan Standard Time         | +02:00             | 0                |
| Kaliningrad Standard Time         | +02:00             | 0                |
| Sudan Standard Time               | +02:00             | 0                |
| Libya Standard Time               | +02:00             | 0                |
| Namibia Standard Time             | +03:00             | 0                |
| Jordan Standard Time              | +03:00             | 0                |
| Arabic Standard Time              | +03:00             | 0                |
| Turkey Standard Time              | +03:00             | 0                |
| Arab Standard Time                | +03:00             | 0                |
| Belarus Standard Time             | +03:00             | 0                |
| Russian Standard Time             | +03:00             | 0                |
| E. Africa Standard Time           | +03:00             | 0                |
| Volgograd Standard Time           | +03:30             | 0                |
| Iran Standard Time                | +04:00             | 0                |
| Arabian Standard Time             | +04:00             | 0                |
| Astrakhan Standard Time           | +04:00             | 0                |
| Azerbaijan Standard Time          | +04:00             | 0                |
| Russia Time Zone 3                | +04:00             | 0                |
| Mauritius Standard Time           | +04:00             | 0                |
| Saratov Standard Time             | +04:00             | 0                |
| Georgian Standard Time            | +04:00             | 0                |
| Caucasus Standard Time            | +04:30             | 0                |
| Afghanistan Standard Time         | +05:00             | 0                |
| West Asia Standard Time           | +05:00             | 0                |
| Ekaterinburg Standard Time        | +05:00             | 0                |
| Pakistan Standard Time            | +05:00             | 0                |
| Qyzylorda Standard Time           | +05:30             | 0                |
| India Standard Time               | +05:30             | 0                |
| Sri Lanka Standard Time           | +05:45             | 0                |
| Nepal Standard Time               | +06:00             | 0                |
| Central Asia Standard Time        | +06:00             | 0                |
| Bangladesh Standard Time          | +06:00             | 0                |
| Omsk Standard Time                | +06:30             | 0                |
| Myanmar Standard Time             | +07:00             | 0                |
| SE Asia Standard Time             | +07:00             | 0                |
| Altai Standard Time               | +07:00             | 0                |
| W. Mongolia Standard Time         | +07:00             | 0                |
| North Asia Standard Time          | +07:00             | 0                |
| N. Central Asia Standard Time     | +07:00             | 0                |
| Tomsk Standard Time               | +08:00             | 0                |
| China Standard Time               | +08:00             | 0                |
| North Asia East Standard Time     | +08:00             | 0                |
| Singapore Standard Time           | +08:00             | 0                |
| W. Australia Standard Time        | +08:00             | 0                |
| Taipei Standard Time              | +08:00             | 0                |
| Ulaanbaatar Standard Time         | +08:45             | 0                |
| Aus Central W. Standard Time      | +09:00             | 0                |
| Transbaikal Standard Time         | +09:00             | 0                |
| Tokyo Standard Time               | +09:00             | 0                |
| North Korea Standard Time         | +09:00             | 0                |
| Korea Standard Time               | +09:00             | 0                |
| Yakutsk Standard Time             | +10:30             | 0                |
| Cen. Australia Standard Time      | +09:30             | 1                |
| AUS Central Standard Time         | +10:00             | 0                |
| E. Australia Standard Time        | +11:00             | 0                |
| AUS Eastern Standard Time         | +10:00             | 1                |
| West Pacific Standard Time        | +11:00             | 0                |
| Tasmania Standard Time            | +10:00             | 1                |
| Vladivostok Standard Time         | +11:00             | 0                |
| Lord Howe Standard Time           | +11:00             | 1                |
| Bougainville Standard Time        | +11:00             | 0                |
| Russia Time Zone 10               | +11:00             | 0                |
| Magadan Standard Time             | +12:00             | 0                |
| Norfolk Standard Time             | +11:00             | 1                |
| Sakhalin Standard Time            | +11:00             | 0                |
| Central Pacific Standard Time     | +12:00             | 0                |
| Russia Time Zone 11               | +13:00             | 0                |
| New Zealand Standard Time         | +12:00             | 1                |
| UTC+12                            | +12:00             | 0                |
| Fiji Standard Time                | +12:00             | 0                |
| Kamchatka Standard Time           | +13:45             | 0                |
| Chatham Islands Standard Time     | +13:00             | 1                |
| UTC+13                            | +13:00             | 0                |
| Tonga Standard Time               | +14:00             | 0                |
| Samoa Standard Time               | +14:00             | 1                |
| Line Islands Standard Time        | +14:00             | 0                |  
+-----------------------------------+--------------------+------------------+

Example

Assume we have created a table with the name STUDENTS in the SQL database using the CREATE statement as shown in the query below −

SQL> CREATE TABLE STUDENTS(ID INT NOT NULL, NAME VARCHAR (200) NOT NULL, AGE INT NOT NULL);	

Now, let us insert some records in the STUDENTS table using INSERT statements as shown in the query below −

SQL> INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(1, 'Dhruv', '20');
INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(2, 'Arjun', '23');
INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(3, 'Dev', '25');
INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(4, 'Riya', '19');
INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(5, 'Aarohi','24');
INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(6, 'Lisa', '20');
INSERT INTO STUDENTS(ID, NAME, AGE) VALUES(7, 'Roy', '24');

We can verify whether the table is created or not using the following query −

SQL> SELECT * FROM STUDENTS;

The table STUDENTS is successfully created in the SQL database.

+----+--------+-----+
| ID | NAME   | AGE |
+----+--------+-----+
| 1  | Dhruv  | 20  |
| 2  | Arjun  | 23  |
| 3  | Dev    | 25  |
| 4  | Riya   | 19  | 
| 5  | Aarohi | 24  |
| 6  | Lisa   | 20  | 
| 7  | Roy    | 24  |
+----+--------+-----+

We can retrieve the current time zone ids of the students using the following query −

SQL> SELECT *, CURRENT_TIMEZONE_ID() AS CURRENT_TIMEZONE_IDS FROM STUDENTS;

Output

The output for the above query is produced as given below −

+----+--------+-----+----------------------+
| ID | NAME   | AGE | CURRENT_TIMEZONE_IDS |
-----+--------+-----+----------------------+
| 1  | Dhruv  | 20  | India Standard Time  |
| 2  | Arjun  | 23  | India Standard Time  |
| 3  | Dev    | 25  | India Standard Time  |
| 4  | Riya   | 19  | India Standard Time  | 
| 5  | Aarohi | 24  | India Standard Time  |
| 6  | Lisa   | 20  | India Standard Time  |
| 7  | Roy    | 24  | India Standard Time  |
+----+--------+-----+----------------------+
sql-date-functions.htm
Advertisements