All Products
Search
Document Center

PolarDB:Date/Time types

Last Updated:Mar 28, 2026

PolarDB for Oracle supports seven date/time types for calendar dates, times of day, timestamps, and time intervals. All types accept flexible input formats and support precision down to the microsecond.

Supported types

TypeStorageDescriptionRangeResolution
timestamp [ (p) ] [ without time zone ]8 bytesDate and time, no time zone4713 BC – 294276 AD1 microsecond
timestamp [ (p) ] with time zone8 bytesDate and time, with time zone4713 BC – 294276 AD1 microsecond
date4 bytesCalendar date only4713 BC – 5874897 AD1 day
time [ (p) ] [ without time zone ]8 bytesTime of day only00:00:00 – 24:00:001 microsecond
time [ (p) ] with time zone12 bytesTime of day with time zone00:00:00+1559 – 24:00:00-15591 microsecond
INTERVAL DAY TO SECOND [(p)]1 bytesDuration from days to seconds-178000000 – 178000000 years1 microsecond
INTERVAL YEAR TO MONTH6 bytesDuration from years to months-178000000 – 178000000 years1 microsecond

Type aliases:

  • timestamp is equivalent to timestamp without time zone per the SQL standard.

  • timestamptz is an accepted abbreviation for timestamp with time zone (a PostgreSQL extension).

Precision (p)

The optional precision value p specifies the number of fractional digits retained in the seconds field. It applies to time, timestamp, and interval types, and ranges from 0 to 6. By default, there is no explicit bound on precision. If no precision is specified in a constant specification, it defaults to the precision of the literal value (but not more than 6 digits).

Interval field restrictions

The interval type accepts an optional field specifier to restrict which date/time components are stored:

YEAR | MONTH | DAY | HOUR | MINUTE | SECOND
YEAR TO MONTH | DAY TO HOUR | DAY TO MINUTE | DAY TO SECOND
HOUR TO MINUTE | HOUR TO SECOND | MINUTE TO SECOND

When both a field specifier and p are specified, the specifier must include SECOND, because precision applies only to the seconds field.

Choose a type

GoalRecommended type
Store a timestamp with time zone awarenesstimestamp with time zone (timestamptz)
Store a timestamp in a fixed time zone contexttimestamp without time zone
Store a calendar date onlydate
Store time of day onlytime without time zone
Store a duration in days to secondsINTERVAL DAY TO SECOND
Store a duration in years to monthsINTERVAL YEAR TO MONTH

Avoid time with time zone. The SQL standard defines it, but time zone offsets have little meaning without an associated date—daylight saving time boundaries vary by date. Use date, time, timestamp without time zone, and timestamp with time zone to cover all date/time needs.

timestamp variants: timestamp without time zone stores the value as given, with no time zone conversion. timestamp with time zone stores values internally in UTC and converts them to the session time zone on display.

Date input

Date and time literals must be enclosed in single quotes. The SQL syntax is:

type [ (p) ] 'value'

Date input is accepted in almost any reasonable format, including ISO 8601, SQL-compatible, and traditional PostgreSQL formats. For ambiguous formats, set the DateStyle parameter to control the interpretation order:

  • MDY — month/day/year

  • DMY — day/month/year

  • YMD — year/month/day

ExampleDescription
1999-01-08ISO 8601; January 8 in any mode (recommended)
January 8, 1999Unambiguous in any DateStyle mode
1/8/1999January 8 in MDY mode; August 1 in DMY mode
1/18/1999January 18 in MDY mode; rejected in other modes
01/02/03January 2, 2003 in MDY; February 1, 2003 in DMY; February 3, 2001 in YMD
1999-Jan-08January 8 in any mode
Jan-08-1999January 8 in any mode
08-Jan-1999January 8 in any mode
99-Jan-08January 8 in YMD mode; error in other modes
08-Jan-99January 8; error in YMD mode
Jan-08-99January 8; error in YMD mode
19990108ISO 8601; January 8, 1999 in any mode
990108ISO 8601; January 8, 1999 in any mode
1999.008Year and day of year
J2451187Julian date
January 8, 99 BCYear 99 BC

Time input

time alone is equivalent to time without time zone. If a time zone is included in the input for time without time zone, it is silently ignored.

When using a time zone name that involves daylight saving time rules (such as America/New_York), specify the date as well so the engine can determine whether standard or daylight saving time applies. The resulting offset is stored as-is in a time with time zone value and is not adjusted to the active session time zone.

ExampleDescription
04:05:06.789ISO 8601
04:05:06ISO 8601
04:05ISO 8601
040506ISO 8601
04:05 AMSame as 04:05; AM does not affect the stored value
04:05 PMSame as 16:05; input hour must be <= 12
04:05:06.789-8ISO 8601 with time zone as UTC offset
04:05:06-08:00ISO 8601 with time zone as UTC offset
04:05-08:00ISO 8601 with time zone as UTC offset
040506-08ISO 8601 with time zone as UTC offset
040506+0730ISO 8601 with fractional-hour UTC offset
040506+07:30:00UTC offset specified to seconds (not allowed in ISO 8601)
04:05:06 PSTTime zone specified by abbreviation
2003-04-12 04:05:06 America/New_YorkTime zone specified by full name

Time zone input formats:

ExampleDescription
PSTAbbreviation (Pacific Standard Time)
America/New_YorkFull IANA time zone name
PST8PDTPOSIX-style time zone specification
-8:00:00UTC offset for PST
-8:00UTC offset for PST (ISO 8601 extended format)
-800UTC offset for PST (ISO 8601 basic format)
-8UTC offset for PST (ISO 8601 basic format)
zuluMilitary abbreviation for UTC
zShort form of zulu (also ISO 8601)

Timestamp input

Valid timestamp input concatenates a date and a time, followed by an optional time zone and optional AD or BC. The following are all valid:

1999-01-08 04:05:06
1999-01-08 04:05:06 -8:00
January 8 04:05:06 1999 PST

How PostgreSQL determines the type from a literal:

PostgreSQL does not inspect the literal string content to determine its type. Both of the following are treated as timestamp without time zone:

TIMESTAMP '2004-10-19 10:23:54'
TIMESTAMP '2004-10-19 10:23:54+02'   -- time zone offset is ignored

To store a value as timestamp with time zone, specify the type explicitly:

TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02'

How timestamp with time zone stores values:

All timestamp with time zone values are stored internally in UTC. On input, explicit time zone offsets are converted to UTC. If no time zone is specified, the system's TimeZone parameter is assumed and the value is converted to UTC. On output, the stored UTC value is converted to the current timezone and displayed as local time.

To view a timestamp in a different time zone, either change the timezone session variable or use the AT TIME ZONE operator:

SELECT '2004-10-19 10:23:54+02'::timestamptz AT TIME ZONE 'America/New_York';

Conversions between timestamp without time zone and timestamp with time zone treat the timestamp without time zone value as being in the current timezone local time. Specify a different time zone with AT TIME ZONE.

Special values

The following special input strings are recognized for date and time types. infinity and -infinity are stored as distinct internal values; the rest are shorthand notations converted to ordinary date/time values when read.

Input stringValid typesDescription
epochdate, timestamp1970-01-01 00:00:00+00 (Unix system time zero)
infinitydate, timestampLater than all other timestamps
-infinitydate, timestampEarlier than all other timestamps
nowdate, time, timestampCurrent transaction's start time
todaydate, timestampMidnight (00:00) today
tomorrowdate, timestampMidnight (00:00) tomorrow
yesterdaydate, timestampMidnight (00:00) yesterday
allballstime00:00:00.00 UTC

The SQL-standard functions CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, LOCALTIME, and LOCALTIMESTAMP return the current date or time for the corresponding type. These are SQL functions and are not recognized in data input strings.

Warning

now, today, tomorrow, and yesterday work correctly in interactive SQL, but can have surprising behavior when the command is saved to be executed later, for example in prepared statements, views, and function definitions. The string can be converted to a specific time value that continues to be used long after it becomes stale. Use SQL functions instead—for example, CURRENT_DATE + 1 is safer than 'tomorrow'::date.

Date/time output

Set the output format with the DateStyle parameter. Four styles are available; the default is ISO.

StyleDescriptionExample
ISOISO 8601, SQL standard (default)1997-12-17 07:37:16-08
SQLTraditional style12/17/1997 07:37:16.00 PST
PostgresOriginal PostgreSQL styleWed Dec 17 07:37:16 1997 PST
GermanRegional style17.12.1997 07:37:16.00 PST
ISO 8601 specifies uppercase T between date and time. PostgreSQL accepts that on input but outputs a space instead, for readability and consistency with RFC 3339.

The datestyle parameter also controls input ordering for ambiguous formats:

datestyle settingInput orderingExample output
SQL, DMYday/month/year17/12/1997 15:37:16.00 CET
SQL, MDYmonth/day/year12/17/1997 07:37:16.00 PST
Postgres, DMYday/month/yearWed 17 Dec 07:37:16 1997 PST

For more flexible formatting, use the to_char function.

Time zones

PolarDB for Oracle uses the IANA (Olson) time zone database for historical time zone rules. All timezone-aware values are stored internally in UTC and converted to the time zone specified by the TimeZone parameter before display.

Three forms are accepted when specifying a time zone:

  • Full time zone name — for example, America/New_York. Recognized names are listed in the pg_timezone_names view. Full names encode daylight saving time transition rules, so the UTC offset they represent can vary by date.

  • Time zone abbreviation — for example, PST. Abbreviations represent a fixed UTC offset and do not encode daylight saving time rules. Recognized abbreviations are listed in the pg_timezone_abbrevs view. You cannot use abbreviations as the value of the TimeZone or log_timezone configuration parameters, but they are accepted in date/time input values and with the AT TIME ZONE operator.

  • POSIX-style specification — use this only when no suitable IANA time zone entry is available.

Abbreviations vs. full names: The difference matters when daylight saving time is in effect. For example, 2014-06-04 12:00 America/New_York and 2014-06-04 12:00 EDT both represent noon Eastern Daylight Time (UTC-4) on that date. But 2014-06-04 12:00 EST always means noon Eastern Standard Time (UTC-5), regardless of the date—so on June 4 it refers to a different instant in time.

Some jurisdictions have used the same abbreviation for different UTC offsets at different times. For example, MSK has meant UTC+3 in some years and UTC+4 in others. PostgreSQL interprets such abbreviations according to what they meant on the specified date.

Time zone names and abbreviations are recognized case-insensitively and are loaded from configuration files under .../share/timezone/ and .../share/timezonesets/.

Setting the session time zone:

-- Set time zone for the current session
SET TIME ZONE 'America/New_York';

-- Equivalent syntax
SET TIMEZONE TO 'America/New_York';

The PGTZ environment variable can be set by libpq clients to send a SET TIME ZONE command automatically upon connection.

Interval input

Interval values can be written in three formats.

Verbose syntax:

[@] quantity unit [quantity unit...] [direction]
  • quantity — a number, optionally signed

  • unitmicrosecond, millisecond, second, minute, hour, day, week, month, year, decade, century, millennium, or their abbreviations and plurals

  • directionago (negates all fields) or empty

  • The leading @ is optional

Days, hours, minutes, and seconds can be specified without unit labels. '1 12:59:10' is equivalent to '1 day 12 hours 59 min 10 sec'. A combination of years and months can be written with a dash: '200-10' is equivalent to '200 years 10 months'.

ISO 8601 format with designators:

P quantity unit [quantity unit...] [T [quantity unit...]]

The string must begin with P. The T separator introduces time-of-day units. The meaning of M depends on whether it appears before or after T.

AbbreviationMeaning
YYears
MMonths (before T)
WWeeks
DDays
HHours
MMinutes (after T)
SSeconds

ISO 8601 alternative format:

P [years-months-days] [T hours:minutes:seconds]

Input examples:

ExampleDescription
1-2SQL standard format: 1 year 2 months
3 4:05:06SQL standard format: 3 days 4 hours 5 minutes 6 seconds
1 year 2 months 3 days 4 hours 5 minutes 6 secondsTraditional PostgreSQL format
P1Y2M3DT4H5M6SISO 8601 format with designators
P0001-02-03T04:05:06ISO 8601 alternative format

Field specifier interaction:

When writing an interval with a field specifier, unmarked quantities are interpreted relative to the least significant field. INTERVAL '1' YEAR reads as 1 year; INTERVAL '1' reads as 1 second. Field values beyond the least significant allowed field are silently discarded: INTERVAL '1 day 2:03:04' HOUR TO MINUTE drops the seconds field but retains the day field.

Mixed-sign intervals:

According to the SQL standard, all fields of an interval must share the same sign. PostgreSQL traditionally allows fields to have different signs and treats each field as independently signed. If IntervalStyle is set to sql_standard, a leading sign is considered to apply to all fields (but only if no additional signs appear); otherwise the traditional PostgreSQL interpretation is used. To avoid ambiguity when any field is negative, attach an explicit sign to each field.

Fractional units:

Interval values support fractional input, but the internal representation uses only three integer units: months, days, and microseconds.

  • Fractional units larger than months are truncated to whole months: '1.5 years' becomes '1 year 6 mons'.

  • Fractional weeks and days are converted assuming 30 days per month and 24 hours per day: '1.75 months' becomes 1 mon 22 days 12:00:00.

  • Only seconds are displayed as fractional on output.

This storage model can produce unexpected results when extracting components:

SELECT EXTRACT(hours FROM '80 minutes'::interval);
-- Result: 1

SELECT EXTRACT(days FROM '80 hours'::interval);
-- Result: 0

Use justify_days and justify_hours to normalize days and hours that overflow their standard ranges.

Interval output

Set the interval output format with SET intervalstyle. The default is postgres.

StyleYear-month intervalDay-time intervalMixed interval
sql_standard1-23 4:05:06-1-2 +3 -4:05:06
postgres1 year 2 mons3 days 04:05:06-1 year -2 mons +3 days -04:05:06
postgres_verbose@ 1 year 2 mons@ 3 days 4 hours 5 mins 6 secs@ 1 year 2 mons -3 days 4 hours 5 mins 6 secs ago
iso_8601P1Y2MP3DT4H5M6SP-1Y-2M3DT-4H-5M-6S

The sql_standard style produces SQL-standard-compliant output when the interval value is year-month only or day-time only with no mixed signs. Otherwise it outputs a year-month literal string followed by a day-time literal string with explicit signs to disambiguate.