codekingpro/portable-devtools
115k
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!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>3 Date/time input strings are decoded using the following procedure.4 </p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p>5 Break the input string into tokens and categorize each token as6 a string, time, time zone, or number.7 </p><ol type="a" class="substeps"><li class="step"><p>8 If the numeric token contains a colon (<code class="literal">:</code>), this is9 a time string. Include all subsequent digits and colons.10 </p></li><li class="step"><p>11 If the numeric token contains a dash (<code class="literal">-</code>), slash12 (<code class="literal">/</code>), or two or more dots (<code class="literal">.</code>), this is13 a date string which might have a text month. If a date token has14 already been seen, it is instead interpreted as a time zone15 name (e.g., <code class="literal">America/New_York</code>).16 </p></li><li class="step"><p>17 If the token is numeric only, then it is either a single field18 or an ISO 8601 concatenated date (e.g.,19 <code class="literal">19990113</code> for January 13, 1999) or time20 (e.g., <code class="literal">141516</code> for 14:15:16).21 </p></li><li class="step"><p>22 If the token starts with a plus (<code class="literal">+</code>) or minus23 (<code class="literal">-</code>), then it is either a numeric time zone or a special24 field.25 </p></li></ol></li><li class="step"><p>26 If the token is an alphabetic string, match up with possible strings:27 </p><ol type="a" class="substeps"><li class="step"><p>28 See if the token matches any known time zone abbreviation.29 These abbreviations are supplied by the configuration file30 described in <a class="xref" href="datetime-config-files.html" title="B.4. Date/Time Configuration Files">Section B.4</a>.31 </p></li><li class="step"><p>32 If not found, search an internal table to match33 the token as either a special string (e.g., <code class="literal">today</code>),34 day (e.g., <code class="literal">Thursday</code>),35 month (e.g., <code class="literal">January</code>),36 or noise word (e.g., <code class="literal">at</code>, <code class="literal">on</code>).37 </p></li><li class="step"><p>38 If still not found, throw an error.39 </p></li></ol></li><li class="step"><p>40 When the token is a number or number field:41 </p><ol type="a" class="substeps"><li class="step"><p>42 If there are eight or six digits,43 and if no other date fields have been previously read, then interpret44 as a <span class="quote">“<span class="quote">concatenated date</span>”</span> (e.g.,45 <code class="literal">19990118</code> or <code class="literal">990118</code>).46 The interpretation is <code class="literal">YYYYMMDD</code> or <code class="literal">YYMMDD</code>.47 </p></li><li class="step"><p>48 If the token is three digits49 and a year has already been read, then interpret as day of year.50 </p></li><li class="step"><p>51 If four or six digits and a year has already been read, then52 interpret as a time (<code class="literal">HHMM</code> or <code class="literal">HHMMSS</code>).53 </p></li><li class="step"><p>54 If three or more digits and no date fields have yet been found,55 interpret as a year (this forces yy-mm-dd ordering of the remaining56 date fields).57 </p></li><li class="step"><p>58 Otherwise the date field ordering is assumed to follow the59 <code class="varname">DateStyle</code> setting: mm-dd-yy, dd-mm-yy, or yy-mm-dd.60 Throw an error if a month or day field is found to be out of range.61 </p></li></ol></li><li class="step"><p>62 If BC has been specified, negate the year and add one for63 internal storage. (There is no year zero in the Gregorian64 calendar, so numerically 1 BC becomes year zero.)65 </p></li><li class="step"><p>66 If BC was not specified, and if the year field was two digits in length,67 then adjust the year to four digits. If the field is less than 70, then68 add 2000, otherwise add 1900.69 70 </p><div class="tip"><h3 class="title">Tip</h3><p>71 Gregorian years AD 1–99 can be entered by using 4 digits with leading72 zeros (e.g., <code class="literal">0099</code> is AD 99).73 </p></div><p>74 </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>