---
title: "Time zone setting and time zone library"
description: "Configure time zones in CoraDB: timezone and server_timezone, SET TIME ZONE, updating the IANA library with make_tz, and JDBC."
url: "https://www.coradb.ai/manual/sql/i18n_timezone.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/i18n_timezone.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb timezone, server_timezone, set time zone, iana time zone, tzdata, make_tz, gen_tz, timezone_checksum, jdbc timezone, CORADBTimestamptz"
---

# Time zone setting and time zone library

## Timezone setting

Two system parameters control time zones (see [Time zone parameters](https://www.coradb.ai/manual/admin/config_sql.html#timezone-parameter)):

| Parameter | Applies to | Default |
|---|---|---|
| [timezone](https://www.coradb.ai/manual/admin/config_sql.html#timezone) | A session | The value of **server_timezone** |
| [server_timezone](https://www.coradb.ai/manual/admin/config_sql.html#server_timezone) | The database server | The operating system's time zone |

A session changes its own time zone with **SET TIME ZONE** or by setting the parameter:

```sql
SET TIME ZONE 'Europe/Bucharest';
SET TIME ZONE '+02:00';
SET SYSTEM PARAMETERS 'timezone=Europe/Bucharest';
```

The session time zone affects the types **TIMESTAMP**, **TIMESTAMPLTZ** and **DATETIMELTZ**, the conversion of values without time zone to the time zone types, and functions such as **SYS_DATETIME**. See [Date/time types with time zone](https://www.coradb.ai/manual/sql/datatype_datetime.html#datetime-types-with-timezone) and [Time zone functions](https://www.coradb.ai/manual/sql/datatype_datetime.html#time-zone-functions).

Time zones written as region names (`Europe/Bucharest`) need the time zone library, which contains the IANA time zone database. A library is installed with CoraDB. Because governments change offsets and daylight-saving rules, update the library from time to time as described below. Offsets such as `+02:00` do not need the library.


## Compiling timezone library

To update the time zone library with the latest IANA data, stop the CoraDB service, then:

### Windows

1. Download the latest *Time Zone Data* (`tzdata*.tar.gz`) from <https://www.iana.org/time-zones>.
2. Extract it into `%CORADB%\timezones\tzdata`.
3. Run `make_tz_x64.bat` from `%CORADB%\bin`. It creates `libcoradb_timezones.dll` in `%CORADB%\lib`.

   ```text
   make_tz_x64.bat
   ```

The script needs Microsoft Visual Studio with the C++ tools, like `make_locale`.

### Linux

1. Download the latest *Time Zone Data* from <https://www.iana.org/time-zones>.
2. Extract it into `$CORADB/timezones/tzdata`.
3. Run `make_tz.sh`. It creates `libcoradb_timezones.so` in `$CORADB/lib`.

   ```text
   make_tz.sh
   ```

`make_tz.sh -h` shows the options: `-t` target (64-bit), `-m release|debug`, and `-g new|extend`. On Windows the corresponding arguments are `/release`, `/debug`, `/new` and `/extend`.


### Timezone library and database compatibility

The library contains an MD5 checksum of its time zone data. Every database stores the checksum of the library it was created with, in the `timezone_checksum` column of `db_root`. A database cannot be used with a library whose checksum differs: after rebuilding the library with new data, either create new databases, or use the *extend* mode, which keeps existing databases usable:

1. It builds a library that merges the old and the new data: regions that no longer exist in the new data are kept, so that values stored in the database remain valid.
2. It updates values stored in the databases where a changed offset or daylight-saving rule makes the old encoding wrong, and stores the new checksum.

```text
make_tz.sh -g extend        # Linux
make_tz_x64.bat /extend     # Windows
```

The extend mode processes every database listed in `databases.txt` (in `$CORADB_DATABASES`), by running `coradb gen_tz -g extend <database>` for each. If one fails, the script stops, and databases already processed may need to be restored from backup. Take a backup before you start.

When several users share one CoraDB installation, the extend can only update the databases that the user running it can access and that are listed in that user's `databases.txt`. Either give that user access to all database directories and the same `CORADB_DATABASES`, or run the extend once per user:

1. Back up the time zone library and `databases.txt`;
2. Remove from `databases.txt` all databases except the current user's;
3. Run the extend;
4. Restore `databases.txt` and, for all users except the last, the time zone library.


### Usage of timezone data types with JDBC

The JDBC driver takes all time zone information from the CoraDB server. Java and CoraDB both use IANA data, but region names and rules may differ between versions, so do not mix Java's time zone handling with CoraDB's.

Values of all time zone types are returned as `coradb.sql.CORADBTimestamptz` objects. To insert one:

```java
String datetime = "2000-01-01 01:02:03.123";
CORADBTimestamptz tz = CORADBTimestamptz.valueOf(datetime, true, "Europe/Kiev");   // true: DATETIME precision
PreparedStatement ps = conn.prepareStatement("INSERT INTO event_log VALUES (?)");
ps.setObject(1, tz);
ps.executeUpdate();
```

To read one:

```java
ResultSet rs = conn.createStatement().executeQuery("SELECT happened_at FROM event_log");
while (rs.next()) {
    CORADBTimestamptz value = (CORADBTimestamptz) rs.getObject(1);
    System.out.println(value);
}
```

A `CORADBTimestamptz` stores its local date and time as if they were UTC, in milliseconds like `java.util.Date`, and keeps the time zone separately. `getTime()` therefore returns the wall-clock value encoded as UTC, while `getUnixTime()` returns the real moment, in seconds since the Unix epoch, taking the time zone into account:

```java
CORADBTimestamptz tz = CORADBTimestamptz.valueOf("2000-01-01 01:02:03.123", true, "Asia/Seoul");
System.out.println(tz.getTime());
System.out.println(tz.getUnixTime());
```
