@@ -6769,9 +6769,9 @@ SELECT (DATE '2001-10-30', DATE '2001-10-30') OVERLAPS
6769
6769
<para>
6770
6770
When adding an <type>interval</type> value to (or subtracting an
6771
6771
<type>interval</type> value from) a <type>timestamp with time zone</type>
6772
- value, the days component advances ( or decrements) the date of the
6772
+ value, the days component advances or decrements the date of the
6773
6773
<type>timestamp with time zone</type> by the indicated number of days.
6774
- Across daylight saving time changes (with the session time zone set to a
6774
+ Across daylight saving time changes (when the session time zone is set to a
6775
6775
time zone that recognizes DST), this means <literal>interval '1 day'</literal>
6776
6776
does not necessarily equal <literal>interval '24 hours'</literal>.
6777
6777
For example, with the session time zone set to <literal>CST7CDT</literal>,
@@ -6785,8 +6785,8 @@ SELECT (DATE '2001-10-30', DATE '2001-10-30') OVERLAPS
6785
6785
</para>
6786
6786
6787
6787
<para>
6788
- Note there can be ambiguity in the <literal>months</> returned by
6789
- <function>age</> because different months have a different number of
6788
+ Note there can be ambiguity in the <literal>months</> field returned by
6789
+ <function>age</> because different months have different numbers of
6790
6790
days. <productname>PostgreSQL</>'s approach uses the month from the
6791
6791
earlier of the two dates when calculating partial months. For example,
6792
6792
<literal>age('2004-06-01', '2004-04-30')</> uses April to yield
@@ -6795,27 +6795,30 @@ SELECT (DATE '2001-10-30', DATE '2001-10-30') OVERLAPS
6795
6795
</para>
6796
6796
6797
6797
<para>
6798
- Subtraction of dates and timestamps can also be complex. The most
6799
- accurate way to perform subtraction is to convert each value to a number
6800
- of seconds using <literal>EXTRACT(EPOCH FROM ...)</> and compute the
6798
+ Subtraction of dates and timestamps can also be complex. One conceptually
6799
+ simple way to perform subtraction is to convert each value to a number
6800
+ of seconds using <literal>EXTRACT(EPOCH FROM ...)</>, then subtract the
6801
+ results; this produces the
6801
6802
number of <emphasis>seconds</> between the two values. This will adjust
6802
6803
for the number of days in each month, timezone changes, and daylight
6803
- saving time adjustments. Operator subtraction of date or timestamp
6804
- values returns the number of days (24-hours) and hours/minutes/seconds
6804
+ saving time adjustments. Subtraction of date or timestamp
6805
+ values with the <quote><literal>-</></quote> operator
6806
+ returns the number of days (24-hours) and hours/minutes/seconds
6805
6807
between the values, making the same adjustments. The <function>age</>
6806
6808
function returns years, months, days, and hours/minutes/seconds,
6807
6809
performing field-by-field subtraction and then adjusting for negative
6808
- field values. The following queries, produced with <literal>timezone
6809
- = 'US/Eastern'</> and including a daylight saving time change,
6810
- illustrates these issues:
6810
+ field values. The following queries illustrate the differences in these
6811
+ approaches. The sample results were produced with <literal>timezone
6812
+ = 'US/Eastern'</>; there is a daylight saving time change between the
6813
+ two dates used:
6811
6814
</para>
6812
6815
6813
6816
<screen>
6814
6817
SELECT EXTRACT(EPOCH FROM timestamptz '2013-07-01 12:00:00') -
6815
6818
EXTRACT(EPOCH FROM timestamptz '2013-03-01 12:00:00');
6816
6819
<lineannotation>Result: </lineannotation><computeroutput>10537200</computeroutput>
6817
6820
SELECT (EXTRACT(EPOCH FROM timestamptz '2013-07-01 12:00:00') -
6818
- EXTRACT(EPOCH FROM timestamptz '2013-03-01 12:00:00'))
6821
+ EXTRACT(EPOCH FROM timestamptz '2013-03-01 12:00:00'))
6819
6822
/ 60 / 60 / 24;
6820
6823
<lineannotation>Result: </lineannotation><computeroutput>121.958333333333</computeroutput>
6821
6824
SELECT timestamptz '2013-07-01 12:00:00' - timestamptz '2013-03-01 12:00:00';
0 commit comments