Current File : //usr/share/doc/postgresql-9.2.24/html/datetime-input-rules.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Date/Time Input Interpretation</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.2.24 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Date/Time Support"
HREF="datetime-appendix.html"><LINK
REL="PREVIOUS"
TITLE="Date/Time Support"
HREF="datetime-appendix.html"><LINK
REL="NEXT"
TITLE="Date/Time Key Words"
HREF="datetime-keywords.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2017-11-06T22:43:11"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.2.24 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="Date/Time Support"
HREF="datetime-appendix.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="datetime-appendix.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Appendix B. Date/Time Support</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="Date/Time Key Words"
HREF="datetime-keywords.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="DATETIME-INPUT-RULES"
>B.1. Date/Time Input Interpretation</A
></H1
><P
> The date/time type inputs are all decoded using the following procedure.
</P
><DIV
CLASS="PROCEDURE"
><OL
TYPE="1"
><LI
CLASS="STEP"
><P
> Break the input string into tokens and categorize each token as
a string, time, time zone, or number.
</P
><OL
CLASS="SUBSTEPS"
TYPE="a"
><LI
CLASS="STEP"
><P
> If the numeric token contains a colon (<TT
CLASS="LITERAL"
>:</TT
>), this is
a time string. Include all subsequent digits and colons.
</P
></LI
><LI
CLASS="STEP"
><P
> If the numeric token contains a dash (<TT
CLASS="LITERAL"
>-</TT
>), slash
(<TT
CLASS="LITERAL"
>/</TT
>), or two or more dots (<TT
CLASS="LITERAL"
>.</TT
>), this is
a date string which might have a text month. If a date token has
already been seen, it is instead interpreted as a time zone
name (e.g., <TT
CLASS="LITERAL"
>America/New_York</TT
>).
</P
></LI
><LI
CLASS="STEP"
><P
> If the token is numeric only, then it is either a single field
or an ISO 8601 concatenated date (e.g.,
<TT
CLASS="LITERAL"
>19990113</TT
> for January 13, 1999) or time
(e.g., <TT
CLASS="LITERAL"
>141516</TT
> for 14:15:16).
</P
></LI
><LI
CLASS="STEP"
><P
> If the token starts with a plus (<TT
CLASS="LITERAL"
>+</TT
>) or minus
(<TT
CLASS="LITERAL"
>-</TT
>), then it is either a numeric time zone or a special
field.
</P
></LI
></OL
></LI
><LI
CLASS="STEP"
><P
> If the token is a text string, match up with possible strings:
</P
><OL
CLASS="SUBSTEPS"
TYPE="a"
><LI
CLASS="STEP"
><P
> Do a binary-search table lookup for the token as a time zone
abbreviation.
</P
></LI
><LI
CLASS="STEP"
><P
> If not found, do a similar binary-search table lookup to match
the token as either a special string (e.g., <TT
CLASS="LITERAL"
>today</TT
>),
day (e.g., <TT
CLASS="LITERAL"
>Thursday</TT
>),
month (e.g., <TT
CLASS="LITERAL"
>January</TT
>),
or noise word (e.g., <TT
CLASS="LITERAL"
>at</TT
>, <TT
CLASS="LITERAL"
>on</TT
>).
</P
></LI
><LI
CLASS="STEP"
><P
> If still not found, throw an error.
</P
></LI
></OL
></LI
><LI
CLASS="STEP"
><P
> When the token is a number or number field:
</P
><OL
CLASS="SUBSTEPS"
TYPE="a"
><LI
CLASS="STEP"
><P
> If there are eight or six digits,
and if no other date fields have been previously read, then interpret
as a <SPAN
CLASS="QUOTE"
>"concatenated date"</SPAN
> (e.g.,
<TT
CLASS="LITERAL"
>19990118</TT
> or <TT
CLASS="LITERAL"
>990118</TT
>).
The interpretation is <TT
CLASS="LITERAL"
>YYYYMMDD</TT
> or <TT
CLASS="LITERAL"
>YYMMDD</TT
>.
</P
></LI
><LI
CLASS="STEP"
><P
> If the token is three digits
and a year has already been read, then interpret as day of year.
</P
></LI
><LI
CLASS="STEP"
><P
> If four or six digits and a year has already been read, then
interpret as a time (<TT
CLASS="LITERAL"
>HHMM</TT
> or <TT
CLASS="LITERAL"
>HHMMSS</TT
>).
</P
></LI
><LI
CLASS="STEP"
><P
> If three or more digits and no date fields have yet been found,
interpret as a year (this forces yy-mm-dd ordering of the remaining
date fields).
</P
></LI
><LI
CLASS="STEP"
><P
> Otherwise the date field ordering is assumed to follow the
<TT
CLASS="VARNAME"
>DateStyle</TT
> setting: mm-dd-yy, dd-mm-yy, or yy-mm-dd.
Throw an error if a month or day field is found to be out of range.
</P
></LI
></OL
></LI
><LI
CLASS="STEP"
><P
> If BC has been specified, negate the year and add one for
internal storage. (There is no year zero in the Gregorian
calendar, so numerically 1 BC becomes year zero.)
</P
></LI
><LI
CLASS="STEP"
><P
> If BC was not specified, and if the year field was two digits in length,
then adjust the year to four digits. If the field is less than 70, then
add 2000, otherwise add 1900.
<DIV
CLASS="TIP"
><BLOCKQUOTE
CLASS="TIP"
><P
><B
>Tip: </B
> Gregorian years AD 1-99 can be entered by using 4 digits with leading
zeros (e.g., <TT
CLASS="LITERAL"
>0099</TT
> is AD 99).
</P
></BLOCKQUOTE
></DIV
>
</P
></LI
></OL
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="datetime-appendix.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="datetime-keywords.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Date/Time Support</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="datetime-appendix.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Date/Time Key Words</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>