Overview
Oxla provides you with two data types for handling timestamps:- Timestamp without Time Zone: It allows you to store both date and time.
-
Timestamp with Time Zone: It stores date and time values but does not store time zone information within the database. Instead, it processes the time zone information during operations.
- During INSERT operation, the time zone is ignored. The date and time are stored without considering the time zone.
- During the SELECT operation, the time zone information from the user’s session is also ignored. The data is returned exactly as it is stored without adjusting the time zone.
Important Note:
Keep in mind that all user sessions have a local timezone associated with them, affecting how timestamps
The timezone information is not stored in the database. Consequently, every time a user requests a value of this type, Oxla converts from UTC to the user’s local timezone before displaying it.
Keep in mind that all user sessions have a local timezone associated with them, affecting how timestamps
with time zone values are displayed. The timezone information is not stored in the database. Consequently, every time a user requests a value of this type, Oxla converts from UTC to the user’s local timezone before displaying it.
Important Note:
Oxla relies on timezone information served by host machine operating system. It must be up-to-date in order to ensure correct timestamp conversions, date calculations, and compliance with regional time changes such as daylight saving adjustments.
Oxla relies on timezone information served by host machine operating system. It must be up-to-date in order to ensure correct timestamp conversions, date calculations, and compliance with regional time changes such as daylight saving adjustments.
Format
Thetimestamp with time zone data type has the following format:
YYYY: Four-digit yearMM: One / two-digit monthDD: One / two-digit dayHH: One / two-digit hour (valid values from 00 to 23)MM: One / two-digit minutes (valid values from 00 to 59)SS: One / two-digit seconds (valid values from 00 to 59)[.SSSSSS]: Up to six fractional digits (microsecond precision)+TZ: Time zone offset in the format +/-HH:MM (e.g., +05:30, -08:00)
Examples
Case #1: Create a table
Let’s create a table namedevent_log that consists of a timestamp without a time zone and a timestamp with time zone columns. The values in the event_timestamp_tz are in the “Europe/Moscow” timezone.
Case #2: Display the table
Run theSELECT statement to get all records of the table:
event_timestamp_tz is converted to UTC timezone.
Case #3: Ordering Table by Timestamp
Let’s assume we want to sort the events based on theevent_timestamp column and display the corresponding UTC in the event_timestamp_tz column. Run the following query:
event_timestamp and event_timestamp_tz columns and calculate the corresponding UTC time using the AT TIME ZONE 'UTC' operator.
We then order the results based on the event_timestamp column, giving us a sorted list of events with their corresponding local and UTC times.
AT TIME ZONE Operator
TheAT TIME ZONE operator in timestamp with time zone converts the given timestamp with time zone to the new time zone, with no time zone designation.
Syntax:
-
timestamp: The date and time value with the time zone. -
TIME_ZONE: The target time zone to which the timestamp will be converted. The user’s timezone is fixed to UTC.