Appendix A. Date/Time Support

Table of Contents
A.1. Time Zones
A.2. History of Units

A.1. Time Zones

PostgreSQL contains internal tabular information for time zone decoding, since there is no *nix standard system interface to provide access to general, cross-timezone information. The underlying OS is used to provide time zone information for output, however.

Table A-1. PostgreSQL Recognized Time Zones

Time ZoneOffset from UTCDescription
NZDT+13:00New Zealand Daylight Time
IDLE+12:00International Date Line, East
NZST+12:00New Zealand Standard Time
NZT+12:00New Zealand Time
AESST+11:00 Australia Eastern Summer Standard Time
ACSST+10:30 Central Australia Summer Standard Time
CADT+10:30 Central Australia Daylight Savings Time
SADT+10:30South Australian Daylight Time
AEST+10:00 Australia Eastern Standard Time
EAST+10:00 East Australian Standard Time
GST+10:00Guam Standard Time, USSR Zone 9
LIGT+10:00Melbourne, Australia
ACST+09:30 Central Australia Standard Time
SAST+09:30 South Australia Standard Time
CAST+09:30 Central Australia Standard Time
AWSST+9:00 Australia Western Summer Standard Time
JST+9:00Japan Standard Time,USSR Zone 8
KST+9:00Korea Standard Time
WDT+9:00West Australian Daylight Time
MT+8:30Moluccas Time
AWST+8:00 Australia Western Standard Time
CCT+8:00 China Coastal Time
WADT+8:00West Australian Daylight Time
WST+8:00West Australian Standard Time
JT+7:30Java Time
WAST+7:00West Australian Standard Time
CXT+7:00Christmas (Island) Time
IOT+5:00Indian Chagos Time
MVT+5:00Maldives Island Time
TFT+5:00Kerguelen Time
EAST+4:00Antananarivo Savings Time
MUT+4:00Mauritius Island Time
RET+4:00Reunion Island Time
SCT+4:00Mahe Island Time
IT+3:30Iran Time
EAT+3:00Antananarivo, Comoro Time
BT+3:00 Baghdad Time
EETDST+3:00 Eastern Europe Daylight Savings Time
BDST+2:00 British Double Standard Time
CEST+2:00 Central European Savings Time
CETDST+2:00 Central European Daylight Savings Time
EET+2:00 Eastern Europe, USSR Zone 1
FWT+2:00French Winter Time
IST+2:00Israel Standard Time
MEST+2:00Middle Europe Summer Time
METDST+2:00Middle Europe Daylight Time
SST+2:00Swedish Summer Time
BST+1:00 British Summer Time
CET+1:00 Central European Time
DNT+1:00 Dansk Normal Tid
FST+1:00 French Summer Time
MET+1:00Middle Europe Time
MEWT+1:00Middle Europe Winter Time
MEZ+1:00Middle Europe Zone
NOR+1:00Norway Standard Time
SET+1:00Seychelles Time
SWT+1:00Swedish Winter Time
WETDST+1:00Western Europe Daylight Savings Time
GMT0:00Greenwich Mean Time
WET0:00Western Europe
WAT-1:00West Africa Time
NDT-2:30Newfoundland Daylight Time
ADT-03:00 Atlantic Daylight Time
NFT-3:30Newfoundland Standard Time
NST-3:30Newfoundland Standard Time
AST-4:00 Atlantic Standard Time (Canada)
EDT-4:00 Eastern Daylight Time
CDT-5:00 Central Daylight Time
EST-5:00 Eastern Standard Time
CST-6:00 Central Standard Time
MDT-6:00Mountain Daylight Time
MST-7:00Mountain Standard Time
PDT-7:00Pacific Daylight Time
PST-8:00Pacific Standard Time
YDT-8:00Yukon Daylight Time
HDT-9:00Hawaii/Alaska Daylight Time
YST-9:00Yukon Standard Time
AHST-10:00 Alaska-Hawaii Standard Time
CAT-10:00 Central Alaska Time
NT-11:00Nome Time
IDLW-12:00International Date Line, West

A.1.1. Australian Time Zones

Australian time zones and their naming variants account for fully one quarter of all time zones in the PostgreSQL time zone lookup table. There are two naming conflicts with time zones commonly used in the United States, CST and EST.

If the runtime option AUSTRALIAN_TIMEZONES is set then CST, EST, and SAT will be interpreted as Australian timezone names. Without this option, CST and EST are taken as American timezone names, while SAT is interpreted as a noise word indicating Saturday.

Table A-2. PostgreSQL Australian Time Zones

Time ZoneOffset from UTCDescription
CST+10:30Australian Central Standard Time
EST+10:00Australian Eastern Standard Time
SAT+9:30South Australian Standard Time

A.1.2. Date/Time Input Interpretation

The date/time types are all decoded using a common set of routines.

Date/Time Input Interpretation

  1. Break the input string into tokens and categorize each token as a string, time, time zone, or number.

    1. If the token contains a colon (":"), this is a time string.

    2. If the token contains a dash ("-"), slash ("/"), or dot ("."), this is a date string which may have a text month.

    3. If the token is numeric only, then it is either a single field or an ISO-8601 concatenated date (e.g. 19990113 for January 13, 1999) or time (e.g. 141516 for 14:15:16).

    4. If the token starts with a plus ("+") or minus ("-"), then it is either a time zone or a special field.

  2. If the token is a text string, match up with possible strings.

    1. Do a binary-search table lookup for the token as either a special string (e.g. today), day (e.g. Thursday), month (e.g. January), or noise word (e.g. on).

      Set field values and bit mask for fields. For example, set year, month, day for today, and additionally hour, minute, second for now.

    2. If not found, do a similar binary-search table lookup to match the token with a time zone.

    3. If not found, throw an error.

  3. The token is a number or number field.

    1. If there are more than 4 digits, and if no other date fields have been previously read, then interpret as a "concatenated date" (e.g. 19990118). 8 and 6 digits are interpreted as year, month, and day, while 7 and 5 digits are interpreted as year, day of year, respectively.

    2. If the token is three digits and a year has already been decoded, then interpret as day of year.

    3. If four or more digits, then interpret as a year.

    4. If in European date mode, and if the day field has not yet been read, and if the value is less than or equal to 31, then interpret as a day.

    5. If the month field has not yet been read, and if the value is less than or equal to 12, then interpret as a month.

    6. If the day field has not yet been read, and if the value is less than or equal to 31, then interpret as a day.

    7. If two digits or four or more digits, then interpret as a year.

    8. Otherwise, throw an error.

  4. If BC has been specified, negate the year and offset by one for internal storage (there is no year zero in the Gregorian calendar, so numerically 1BC becomes year zero).

  5. If BC was not specified, and if the year field was two digits in length, then adjust the year to 4 digits. If the field was less than 70, then add 2000; otherwise, add 1900.

    Tip: Gregorian years 1-99AD may be entered by using 4 digits with leading zeros (e.g. 0099 is 99AD). Previous versions of PostgreSQL accepted years with three digits and with single digits, but as of version 7.0 the rules have been tightened up to reduce the possibility of ambiguity.