Date/time types: DATE, TIME, TIMESTAMP, DATETIME and time zones
Date/time types
Section titled “Date/time types”Date/time types store a date, a time of day, or both. CoraDB supports the following types:
| Type | Bytes | Min | Max | Notes |
|---|---|---|---|---|
| DATE | 4 | 0001-01-01 | 9999-12-31 | |
| TIME | 4 | 00:00:00 | 23:59:59 | |
| TIMESTAMP | 4 | 1970-01-01 00:00:01 UTC | 2038-01-19 03:14:07 UTC | Stored as seconds since the Unix epoch, shown in the session time zone. |
| DATETIME | 8 | 0001-01-01 00:00:00.000 | 9999-12-31 23:59:59.999 | Millisecond precision. |
| TIMESTAMPLTZ | 4 | As TIMESTAMP | As TIMESTAMP | TIMESTAMP WITH LOCAL TIME ZONE |
| TIMESTAMPTZ | 8 | As TIMESTAMP | As TIMESTAMP | TIMESTAMP WITH TIME ZONE |
| DATETIMELTZ | 8 | 0001-01-01 00:00:00.000 UTC | 9999-12-31 23:59:59.999 UTC | DATETIME WITH LOCAL TIME ZONE |
| DATETIMETZ | 12 | 0001-01-01 00:00:00.000 UTC | 9999-12-31 23:59:59.999 UTC | DATETIME WITH TIME ZONE |
In the e-commerce sample database, orders.order_date and orders.shipped_date are DATE columns, and the since property of the graph edges (for example likes.since) is DATETIME.
Range and resolution
- Times use the 24-hour clock and dates follow the Gregorian calendar. A value that does not exist in either is rejected.
- TIMESTAMP covers 1970-01-01 00:00:01 to 2038-01-19 03:14:07 UTC. In a session at UTC+9 that is 1970-01-01 09:00:01 to 2038-01-19 12:14:07 local time. Use DATETIME for values outside this range or when you need milliseconds.
- For the time zone types the limits apply to the value converted to UTC, so the local limits depend on the time zone.
- TIME and TIMESTAMP have a resolution of one second, DATE of one day, DATETIME of one millisecond. Extra precision in the input is dropped.
Two-digit years
A two-digit year from 00 to 69 means 2000–2069, and 70 to 99 means 1970–1999. A year written with one, three or four digits is taken as is.
SELECT DATE'00-10-31' AS a, DATE'70-10-31' AS b, DATE'0070-10-31' AS c;| a | b | c |
|---|---|---|
| 2000-10-31 | 1970-10-31 | 0070-10-31 |
Zero dates
Zero is not a valid year, month or day, so DATE'0000-10-31' is an error (Invalid date). As an exception, a value whose fields are all zero is accepted: DATE'0000-00-00', TIMESTAMP'0000-00-00 00:00:00', DATETIME'0000-00-00 00:00:00' and the same for the time zone types. For TIMESTAMP, 1970-01-01 00:00:00 UTC is the same value as TIMESTAMP'0000-00-00 00:00:00'.
- Date/time functions given an all-zero argument either return NULL or raise an error, depending on the system parameter return_null_on_function_errors (default
no: error). - Java cannot represent an all-zero date. JDBC handles it according to the
zeroDateTimeBehaviorconnection property (raise an exception, return NULL, or return the minimum value); see Configuration connection.
Display format
The result tables in this manual show dates and times in ISO form (2008-10-31, 13:15:45, 2008-10-31 13:15:45). CoraDB's own text form, used by corasql and by CAST(... AS STRING), is MM/DD/YYYY for dates and hh:mi:ss AM|PM for times, for example 01:15:45 PM 10/31/2008. Drivers return native date/time values that your application formats. Use TO_CHAR or DATE_FORMAT to choose a format in SQL.
When the system parameter intl_date_lang is set, TO_DATE, TO_TIME, TO_DATETIME, TO_TIMESTAMP, DATE_FORMAT, TIME_FORMAT, TO_CHAR and STR_TO_DATE read and write month and day names in that locale. See Statement/type-related parameters.
Explicit conversion
CAST converts between date/time types that share a field:
| From \ to | DATE | TIME | DATETIME | TIMESTAMP |
|---|---|---|---|---|
| DATE | — | no | yes | yes |
| TIME | no | — | no | no |
| DATETIME | yes | yes | — | yes |
| TIMESTAMP | yes | yes | yes | — |
The time zone types follow the rules of their base type. Converting a DATE to DATETIME or TIMESTAMP sets the time to midnight; converting to DATE or TIME drops the other part:
SELECT CAST(DATE'2011-04-20' AS DATETIME) AS a, CAST(DATETIME'2011-04-20 09:10:15.359' AS DATE) AS b, CAST(DATETIME'2011-04-20 09:10:15.359' AS TIME) AS c;| a | b | c |
|---|---|---|
| 2011-04-20 00:00:00.000 | 2011-04-20 | 09:10:15 |
CAST(DATE'2011-04-20' AS TIME) fails with Cannot coerce date '2011-04-20' to type time, and CAST(TIME'09:10:15' AS DATETIME) with Casting time '09:10:15' to type datetime is not supported. For implicit conversions see Implicit type conversion and Arithmetic operations and type casting of DATE/TIME data types.
DATE stores a year, month and day, from 0001-01-01 to 9999-12-31.
DATE'mm/dd[/yyyy]'DATE'[yyyy-]mm-dd'- All fields are integers. If the year is omitted, the current year is used.
- TO_DATE converts a string in any format to a DATE.
- A DEFAULT value can be declared for a column of this type, for example
DEFAULT SYS_DATE.
SELECT DATE'2008-10-31' AS a, DATE'10/31/2008' AS b, DATE'0000-00-00' AS c;| a | b | c |
|---|---|---|
| 2008-10-31 | 2008-10-31 | 0000-00-00 |
DATE'10/31' is October 31 of the current year.
TIME stores an hour, minute and second, from 00:00:00 to 23:59:59.
TIME'hh:mi[:ss] [AM | PM]'- All fields are integers. If the seconds are omitted they are 0.
- Both 12-hour and 24-hour input is accepted. A 24-hour value may carry PM when it agrees with it (
13:15:45 PM), butTIME'13:15:45 AM'is an error (Invalid time). - TO_TIME converts a string in any format to a TIME.
- A DEFAULT value can be declared for a column of this type.
SELECT TIME'00:00:00' AS a, TIME'1:15' AS b, TIME'13:15:45' AS c, TIME'01:15:45 PM' AS d;| a | b | c | d |
|---|---|---|---|
| 00:00:00 | 01:15:00 | 13:15:45 | 13:15:45 |
TIMESTAMP
Section titled “TIMESTAMP”TIMESTAMP stores a date and a time to the second, from 1970-01-01 00:00:01 to 2038-01-19 03:14:07 UTC. The value is kept as seconds since the Unix epoch and shown in the session time zone.
TIMESTAMP'hh:mi[:ss] [AM|PM] mm/dd[/yyyy]'TIMESTAMP'hh:mi[:ss] [AM|PM] [yyyy-]mm-dd'TIMESTAMP'mm/dd[/yyyy] hh:mi[:ss] [AM|PM]'TIMESTAMP'[yyyy-]mm-dd hh:mi[:ss] [AM|PM]'- The time can come before or after the date. If the year is omitted, the current year is used; if the time is omitted, it is midnight.
SYS_TIMESTAMP(alsoSYSTIMESTAMP,CURRENT_TIMESTAMP) returns the current timestamp, for example as a column DEFAULT.- TIMESTAMP and TO_TIMESTAMP convert strings to TIMESTAMP.
- A value outside the range is an error:
TIMESTAMP'2099-10-31 01:15:45 PM'fails withInvalid utime.
SELECT TIMESTAMP'10/31/2008' AS a, TIMESTAMP'13:15:45 10/31/2008' AS b, TIMESTAMP'01:15:45 PM 2008-10-31' AS c, TIMESTAMP'2008-10-31 01:15:45 PM' AS d;| a | b | c | d |
|---|---|---|---|
| 2008-10-31 00:00:00 | 2008-10-31 13:15:45 | 2008-10-31 13:15:45 | 2008-10-31 13:15:45 |
DATETIME
Section titled “DATETIME”DATETIME stores a date and a time to the millisecond, from 0001-01-01 00:00:00.000 to 9999-12-31 23:59:59.999. It does not depend on the session time zone.
DATETIME'hh:mi[:ss[.msec]] [AM|PM] mm/dd[/yyyy]'DATETIME'hh:mi[:ss[.msec]] [AM|PM] [yyyy-]mm-dd'DATETIME'mm/dd[/yyyy] hh:mi[:ss[.msec]] [AM|PM]'DATETIME'[yyyy-]mm-dd hh:mi[:ss[.msec]] [AM|PM]'- The time can come before or after the date. If the year is omitted, the current year is used; if the time is omitted, it is midnight.
SYS_DATETIME(alsoSYSDATETIME, CURRENT_DATETIME, NOW) returns the current date and time, for example as a column DEFAULT.- TO_DATETIME converts a string in any format to DATETIME.
SELECT DATETIME'10/31/2008' AS a, DATETIME'13:15:45 10/31/2008' AS b, DATETIME'2008-10-31 13:15:45.123' AS c, DATETIME'2099-10-31 01:15:45 PM' AS d;| a | b | c | d |
|---|---|---|---|
| 2008-10-31 00:00:00.000 | 2008-10-31 13:15:45.000 | 2008-10-31 13:15:45.123 | 2099-10-31 13:15:45.000 |
Converting strings to date/time values
Section titled “Converting strings to date/time values”Recommended formats
Section titled “Recommended formats”When you convert a string with CAST, or with TO_DATE, TO_TIME, TO_DATETIME or TO_TIMESTAMP without a format argument, write the string in one of these forms. They do not depend on the database locale.
| Type | Formats |
|---|---|
| DATE | YYYY-MM-DD, MM/DD/YYYY |
| TIME | HH:MI:SS [AM|PM] |
| DATETIME | YYYY-MM-DD HH:MI:SS[.msec] [AM|PM], MM/DD/YYYY HH:MI:SS[.msec] [AM|PM], or the time first: HH:MI:SS[.msec] [AM|PM] YYYY-MM-DD |
| TIMESTAMP | As DATETIME, without milliseconds |
For example, WHERE order_date >= '2025-12-01' compares the DATE column with a date, because the string is converted to DATE.
Other accepted formats
Section titled “Other accepted formats”CAST also accepts the following shorter forms.
DATE strings
[year sep] month sep day:2011-04-20, or04-20for April 20 of the current year.- With
/as the separator the order ismonth/day[/year]:04/20/2011,04/20. - Without separators:
YYYYMMDD,YYMMDD,YMMDD,MMDDorMDD. The day always has two digits:20110420and110420are April 20, 2011;420is April 20 of the current year.
TIME strings
[hour]:min[:[sec]][.[msec]] [AM|PM]:09:10:15,09:10, or:10(00:10:00). Milliseconds are accepted and dropped.- Without separators, the digits are read from the right as seconds, minutes and hours:
91015is 09:10:15,1015is 00:10:15, and15or10is that many seconds. - A full date and time without separators (
20110420091015) gives the time part.
DATETIME strings
- A date as above followed by an hour and optional minutes, seconds and milliseconds:
2011-04-20 09,04/20/2011 09,04-20 09. - Without separators:
YYMMDDHHMI[SS[.msec]]orYYYYMMDDHHMISS[.msec], andYYMMDDHwhen the hour has one digit (1104209is 2011-04-20 09:00). The digits are matched to the patterns by length, so201104200910.359(12 digits) is read asYYMMDDHHMISS, that is 2020-11-04 20:09:10.359. - Time first, then date:
09:10:15.359 am 2011-04-20,:10 04/20,09 04-20. In this form the time separator is always:and the date separator is-(yyyy-mm-dd) or/(mm/dd/yyyy).
Rules
- Milliseconds (msec) are kept only by DATETIME; digits after the third are ignored. DATE, TIME and TIMESTAMP drop them.
- A date string without separators, or with any non-alphanumeric separator, is accepted, but the same separator must be used throughout. The date and the time are separated by a space.
- The year can be omitted wherever the format allows; the current year is used. Two-digit years follow the 1970–2069 rule above.
- Converting a date-only string to DATETIME sets the time to midnight. Converting a date-and-time string to DATE or TIME keeps only that part, but the other part must still be valid.
- AM/PM must follow the time, separated by a space. The English markers are always accepted, as well as those of the server locale.
SELECT CAST('91015' AS TIME) AS a, CAST('110420091035.359' AS DATETIME) AS b, CAST('110420091035.359' AS TIMESTAMP) AS c, CAST('20110420' AS DATE) AS d, CAST('2011-04-20 09:10:15' AS TIME) AS e;| a | b | c | d | e |
|---|---|---|---|---|
| 09:10:15 | 2011-04-20 09:10:35.359 | 2011-04-20 09:10:35 | 2011-04-20 | 09:10:15 |
Date/time types with time zone
Section titled “Date/time types with time zone”The time zone types carry time zone information in addition to the date and time. A time zone is written either as an IANA region name, optionally followed by the daylight-saving abbreviation (Europe/Bucharest, Europe/Bucharest EEST), or as an offset from UTC (+09:00).
- TZ types (DATETIMETZ, TIMESTAMPTZ, also written type
WITH TIME ZONE) store the value in UTC together with its time zone (the one written in the value, or the session time zone). They take 4 bytes more than the base type, and always print in their own time zone. - LTZ types (DATETIMELTZ, TIMESTAMPLTZ, also written type
WITH LOCAL TIME ZONE) store the value in UTC only, and print it converted to the session time zone.
| Type | Input | Stored | Output |
|---|---|---|---|
| DATE, TIME, DATETIME | Without time zone | The value as entered | As entered |
| DATETIMETZ | With time zone | UTC + time zone | In the value's own time zone |
| DATETIMELTZ | With time zone | UTC | In the session time zone |
| TIMESTAMP | Without time zone | UTC (input read in the session time zone) | In the session time zone, without zone name |
| TIMESTAMPTZ | With time zone | UTC + time zone | In the value's own time zone |
| TIMESTAMPLTZ | With time zone | UTC | In the session time zone, with zone name |
Range, resolution and literal formats are the same as for the base types.
The session time zone is changed with SET TIME ZONE. The following stores the same wall-clock value, 2015-02-24 12:30, in each type while the session is at UTC+9, and reads it back at UTC+9, UTC+7 and in Europe/Bucharest (UTC+2 in February):
SET TIME ZONE '+09:00';CREATE TABLE tz_demo (a DATETIME, b DATETIMETZ, c DATETIMELTZ, d TIMESTAMP, e TIMESTAMPTZ, f TIMESTAMPLTZ);INSERT INTO tz_demo VALUES (DATETIME'2015-02-24 12:30', DATETIMETZ'2015-02-24 12:30', DATETIMELTZ'2015-02-24 12:30', TIMESTAMP'2015-02-24 12:30', TIMESTAMPTZ'2015-02-24 12:30', TIMESTAMPLTZ'2015-02-24 12:30');SELECT * FROM tz_demo;SET TIME ZONE '+07:00';SELECT * FROM tz_demo;SET TIME ZONE 'Europe/Bucharest';SELECT * FROM tz_demo;| Session | DATETIME | DATETIMETZ | DATETIMELTZ | TIMESTAMP | TIMESTAMPTZ | TIMESTAMPLTZ |
|---|---|---|---|---|---|---|
| +09:00 | 2015-02-24 12:30:00.000 | 2015-02-24 12:30:00.000 +09:00 | 2015-02-24 12:30:00.000 +09:00 | 2015-02-24 12:30:00 | 2015-02-24 12:30:00 +09:00 | 2015-02-24 12:30:00 +09:00 |
| +07:00 | 2015-02-24 12:30:00.000 | 2015-02-24 12:30:00.000 +09:00 | 2015-02-24 10:30:00.000 +07:00 | 2015-02-24 10:30:00 | 2015-02-24 12:30:00 +09:00 | 2015-02-24 10:30:00 +07:00 |
| Europe/Bucharest | 2015-02-24 12:30:00.000 | 2015-02-24 12:30:00.000 +09:00 | 2015-02-24 05:30:00.000 Europe/Bucharest EET | 2015-02-24 05:30:00 | 2015-02-24 12:30:00 +09:00 | 2015-02-24 05:30:00 Europe/Bucharest EET |
DATETIME never changes, the TZ types keep the time zone they were stored with, and TIMESTAMP and the LTZ types follow the session.
Converting between types with and without time zone
| Conversion | Rule |
|---|---|
| String without time zone → TIMESTAMP, TIMESTAMPLTZ, DATETIMELTZ | Read in the session time zone, stored as UTC |
| String without time zone → TIMESTAMPTZ, DATETIMETZ | Read in the session time zone, stored as UTC with the session time zone |
| String without time zone → DATETIME | Stored as written |
| String with time zone → TIMESTAMPLTZ, DATETIMELTZ | Converted from its time zone to UTC |
| String with time zone → TIMESTAMPTZ, DATETIMETZ | Converted to UTC, its time zone is kept |
| String with time zone → TIMESTAMP, DATETIME | Error: the base types do not accept a time zone |
| DATETIME → DATETIMETZ | Read in the session time zone |
| DATETIMETZ → DATETIME | Keeps the date and time of the value's own time zone |
| DATETIMELTZ, TIMESTAMPTZ, TIMESTAMPLTZ → a type without time zone | The date and time in the session time zone |
In a session at Asia/Seoul (UTC+9 all year), for a value written as 2026-07-01 12:00 in Europe/Bucharest (UTC+3 in summer):
SET TIME ZONE 'Asia/Seoul';SELECT CAST(DATETIMETZ'2026-07-01 12:00:00 Europe/Bucharest' AS DATETIME) AS tz_to_dt, CAST(DATETIMELTZ'2026-07-01 12:00:00 Europe/Bucharest' AS DATETIME) AS ltz_to_dt, CAST(DATETIME'2026-07-01 12:00:00' AS DATETIMETZ) AS dt_to_tz, CAST(TIMESTAMPTZ'2026-07-01 12:00:00 Europe/Bucharest' AS TIMESTAMP) AS tstz_to_ts;| tz_to_dt | ltz_to_dt | dt_to_tz | tstz_to_ts |
|---|---|---|---|
| 2026-07-01 12:00:00.000 | 2026-07-01 18:00:00.000 | 2026-07-01 12:00:00.000 Asia/Seoul KST | 2026-07-01 18:00:00 |
When a value is printed, TIMESTAMP and DATETIME never show a time zone, the LTZ types show the session time zone, and the TZ types show their own.
Time zone configuration
Section titled “Time zone configuration”The following system parameters in coradb.conf control time zones. See System parameters.
| Parameter | Meaning | Default |
|---|---|---|
| timezone | Time zone of a session | The value of server_timezone |
| server_timezone | Time zone of the server | The operating system's time zone |
| tz_leap_second_support | Leap second support | no |
A session changes its own time zone with SET TIME ZONE 'Europe/Bucharest' or SET TIME ZONE '+02:00'.
Time zone functions
Section titled “Time zone functions”- DBTIMEZONE: the server time zone.
- SESSIONTIMEZONE: the session time zone.
- FROM_TZ: adds a time zone to a DATETIME value.
- NEW_TIME: converts a value from one time zone to another.
- TZ_OFFSET: the UTC offset of a time zone.
Functions and operators on time zone types
Section titled “Functions and operators on time zone types”Every function and operator that accepts DATETIME, TIMESTAMP or TIME also accepts the corresponding time zone types, and the result keeps the time zone type. As with the base types, a number added to a DATETIME type counts milliseconds and a number added to a TIMESTAMP type counts seconds. In a session at Asia/Seoul:
SET TIME ZONE 'Asia/Seoul';SELECT DATETIMELTZ'09/01/2009 03:30:30 PM' + 1 AS a, TIMESTAMPTZ'09/01/2009 03:30:30 PM' - 1 AS b;| a | b |
|---|---|
| 2009-09-01 15:30:30.001 Asia/Seoul KST | 2009-09-01 15:30:29 Asia/Seoul KST |
An LTZ value is seen in the session time zone. 05:45 in Bucharest on 1986-10-15 (UTC+2 on that date) is 12:45 in Seoul, so EXTRACT returns hour 5 for DATETIMETZ and hour 12 for DATETIMELTZ:
SET TIME ZONE 'Asia/Seoul';SELECT EXTRACT(HOUR FROM DATETIMETZ'10/15/1986 5:45:15.135 AM Europe/Bucharest') AS tz_hour, EXTRACT(HOUR FROM DATETIMELTZ'10/15/1986 5:45:15.135 AM Europe/Bucharest') AS ltz_hour;| tz_hour | ltz_hour |
|---|---|
| 5 | 12 |
Conversion functions for time zone types
Section titled “Conversion functions for time zone types”These functions convert between strings and date/time values, and understand time zone regions (TZR), daylight-saving abbreviations (TZD) and offsets (TZH, TZM):
SELECT DATE_FORMAT(DATETIMETZ'2012-02-02 10:10:10 Europe/Zurich CET', '%TZR %TZD %TZH %TZM') AS fmt, TO_DATETIME_TZ('2001-10-11 02:03:04 AM Europe/Bucharest EEST') AS dt, TO_TIMESTAMP_TZ('2001-10-11 02:03:04 AM Europe/Bucharest') AS ts;| fmt | dt | ts |
|---|---|---|
| Europe/Zurich CET +01 00 | 2001-10-11 02:03:04.000 Europe/Bucharest EEST | 2001-10-11 02:03:04 Europe/Bucharest EEST |
TO_DATETIME_TZ and TO_TIMESTAMP_TZ work like TO_DATETIME and TO_TIMESTAMP, except that the string can contain TZR, TZD, TZH and TZM information.
IANA time zones
Section titled “IANA time zones”CoraDB uses the region names of the IANA (Internet Assigned Numbers Authority) time zone database, which records the history of local time, UTC offsets and daylight-saving rules for locations around the world. It is updated whenever governments change these rules; its maintenance is described in BCP 175. See https://www.iana.org/time-zones.
CoraDB ships with a compiled time zone library. To use a newer version of the database, update the time zone data, compile the library and restart the database; see Compiling timezone library.