You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add two new format fields for use with to_char(), to_date() and
to_timestamp():
- ID for day-of-week
- IDDD for day-of-year
This makes it possible to convert ISO week dates to and from text
fully represented in either week ('IYYY-IW-ID') or day-of-year
('IYYY-IDDD') format.
I have also added an 'isoyear' field for use with extract / date_part.
Brendan Jurd
An ISO week date (as distinct from a Gregorian date) can be specified to <function>to_timestamp</function> and <function>to_date</function> in one of two ways:
4805
+
<itemizedlist>
4806
+
<listitem>
4807
+
<para>
4808
+
Year, week and weekday, for example <literal>to_date('2006-42-4', 'IYYY-IW-ID')</literal> returns the date <literal>2006-10-19</literal>. If you omit the weekday it is assumed to be 1 (Monday).
4809
+
</para>
4810
+
</listitem>
4811
+
<listitem>
4812
+
<para>
4813
+
Year and day of year, for example <literal>to_date('2006-291', 'IYYY-IDDD')</literal> also returns <literal>2006-10-19</literal>.
4814
+
</para>
4815
+
</listitem>
4816
+
</itemizedlist>
4817
+
</para>
4818
+
<para>
4819
+
Attempting to construct a date using a mixture of ISO week and Gregorian date fields is nonsensical, and could yield unexpected results. In the context of an ISO year, the concept of a 'month' or 'day of month' has no meaning. In the context of a Gregorian year, the ISO week has no meaning. Users should take care to keep Gregorian and ISO date specifications separate.
4820
+
</para>
4821
+
</listitem>
4822
+
4794
4823
<listitem>
4795
4824
<para>
4796
4825
Millisecond (<literal>MS</literal>) and microsecond (<literal>US</literal>)
@@ -5776,6 +5805,29 @@ SELECT EXTRACT(HOUR FROM TIMESTAMP '2001-02-16 20:38:40');
5776
5805
</listitem>
5777
5806
</varlistentry>
5778
5807
5808
+
<varlistentry>
5809
+
<term><literal>isoyear</literal></term>
5810
+
<listitem>
5811
+
<para>
5812
+
The <acronym>ISO</acronym> 8601 year that the date falls in (not applicable to intervals).
Each <acronym>ISO</acronym> year begins with the Monday of the week containing the 4th of January, so in early January or late December the <acronym>ISO</acronym> year may be different from the Gregorian year. See the <literal>week</literal> field for more information.
5824
+
</para>
5825
+
<para>
5826
+
This field is not available in PostgreSQL releases prior to 8.3.
0 commit comments