Skip to content

Commit 7489eb4

Browse files
committed
Docs: wording improvements in discussion of timestamp arithmetic.
I started out just to fix the broken markup in commit 1c20857, but got distracted by copy-editing. I see Bruce already fixed the markup, but I'll commit the wordsmithing anyway.
1 parent b642bc5 commit 7489eb4

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

doc/src/sgml/func.sgml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6769,9 +6769,9 @@ SELECT (DATE '2001-10-30', DATE '2001-10-30') OVERLAPS
67696769
<para>
67706770
When adding an <type>interval</type> value to (or subtracting an
67716771
<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
67736773
<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
67756775
time zone that recognizes DST), this means <literal>interval '1 day'</literal>
67766776
does not necessarily equal <literal>interval '24 hours'</literal>.
67776777
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
67856785
</para>
67866786

67876787
<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
67906790
days. <productname>PostgreSQL</>'s approach uses the month from the
67916791
earlier of the two dates when calculating partial months. For example,
67926792
<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
67956795
</para>
67966796

67976797
<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
68016802
number of <emphasis>seconds</> between the two values. This will adjust
68026803
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
68056807
between the values, making the same adjustments. The <function>age</>
68066808
function returns years, months, days, and hours/minutes/seconds,
68076809
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:
68116814
</para>
68126815

68136816
<screen>
68146817
SELECT EXTRACT(EPOCH FROM timestamptz '2013-07-01 12:00:00') -
68156818
EXTRACT(EPOCH FROM timestamptz '2013-03-01 12:00:00');
68166819
<lineannotation>Result: </lineannotation><computeroutput>10537200</computeroutput>
68176820
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'))
68196822
/ 60 / 60 / 24;
68206823
<lineannotation>Result: </lineannotation><computeroutput>121.958333333333</computeroutput>
68216824
SELECT timestamptz '2013-07-01 12:00:00' - timestamptz '2013-03-01 12:00:00';

0 commit comments

Comments
 (0)