1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>B.1. Date/Time Input Interpretation</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="datetime-appendix.html" title="Appendix B. Date/Time Support" /><link rel="next" href="datetime-invalid-input.html" title="B.2. Handling of Invalid or Ambiguous Timestamps" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">B.1. Date/Time Input Interpretation</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="datetime-appendix.html" title="Appendix B. Date/Time Support">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="datetime-appendix.html" title="Appendix B. Date/Time Support">Up</a></td><th width="60%" align="center">Appendix B. Date/Time Support</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="datetime-invalid-input.html" title="B.2. Handling of Invalid or Ambiguous Timestamps">Next</a></td></tr></table><hr /></div><div class="sect1" id="DATETIME-INPUT-RULES"><div class="titlepage"><div><div><h2 class="title" style="clear: both">B.1. Date/Time Input Interpretation <a href="#DATETIME-INPUT-RULES" class="id_link">#</a></h2></div></div></div><p>
Date/time input strings are decoded using the following procedure.
</p><div class="procedure"><ol class="procedure" 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 type="a" class="substeps"><li class="step"><p>
If the numeric token contains a colon (<code class="literal">:</code>), this is
a time string. Include all subsequent digits and colons.
</p></li><li class="step"><p>
If the numeric token contains a dash (<code class="literal">-</code>), slash
(<code class="literal">/</code>), or two or more dots (<code class="literal">.</code>), 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., <code class="literal">America/New_York</code>).
</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.,
<code class="literal">19990113</code> for January 13, 1999) or time
(e.g., <code class="literal">141516</code> for 14:15:16).
</p></li><li class="step"><p>
If the token starts with a plus (<code class="literal">+</code>) or minus
(<code class="literal">-</code>), then it is either a numeric time zone or a special
field.
</p></li></ol></li><li class="step"><p>
If the token is an alphabetic string, match up with possible strings:
</p><ol type="a" class="substeps"><li class="step"><p>
See if the token matches any known time zone abbreviation.
These abbreviations are supplied by the configuration file
described in <a class="xref" href="datetime-config-files.html" title="B.4. Date/Time Configuration Files">Section B.4</a>.
</p></li><li class="step"><p>
If not found, search an internal table to match
the token as either a special string (e.g., <code class="literal">today</code>),
day (e.g., <code class="literal">Thursday</code>),
month (e.g., <code class="literal">January</code>),
or noise word (e.g., <code class="literal">at</code>, <code class="literal">on</code>).
</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 type="a" class="substeps"><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">“<span class="quote">concatenated date</span>”</span> (e.g.,
<code class="literal">19990118</code> or <code class="literal">990118</code>).
The interpretation is <code class="literal">YYYYMMDD</code> or <code class="literal">YYMMDD</code>.
</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 (<code class="literal">HHMM</code> or <code class="literal">HHMMSS</code>).
</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
<code class="varname">DateStyle</code> 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.
</p><div class="tip"><h3 class="title">Tip</h3><p>
Gregorian years AD 1–99 can be entered by using 4 digits with leading
zeros (e.g., <code class="literal">0099</code> is AD 99).
</p></div><p>
</p></li></ol></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="datetime-appendix.html" title="Appendix B. Date/Time Support">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="datetime-appendix.html" title="Appendix B. Date/Time Support">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="datetime-invalid-input.html" title="B.2. Handling of Invalid or Ambiguous Timestamps">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Appendix B. Date/Time Support </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> B.2. Handling of Invalid or Ambiguous Timestamps</td></tr></table></div></body></html>
|