75 lines
5.1 KiB
HTML
75 lines
5.1 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="concept" />
|
||
|
<meta name="DC.Title" content="Increment and decrement dates" />
|
||
|
<meta name="abstract" content="The result of adding a duration to a date, or of subtracting a duration from a date, is itself a date." />
|
||
|
<meta name="description" content="The result of adding a duration to a date, or of subtracting a duration from a date, is itself a date." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafodttaopq.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="rbafodincr" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Increment and decrement dates</title>
|
||
|
</head>
|
||
|
<body id="rbafodincr"><a name="rbafodincr"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Increment and decrement dates</h1>
|
||
|
<div><p>The result of adding a duration to a date, or of subtracting a
|
||
|
duration from a date, is itself a date. </p>
|
||
|
<p>(For the purposes of this operation, a month denotes the equivalent of
|
||
|
a calendar page. Adding months to a date, then, is like turning the pages
|
||
|
of a calendar, starting with the page on which the date appears.) The result
|
||
|
must fall between the dates January 1, 0001, and December 31, 9999, inclusive.
|
||
|
If a duration of years is added or subtracted, only the year portion of the
|
||
|
date is affected. The month is unchanged, as is the day unless the result
|
||
|
would be February 29 of a year that is not a leap year. In this case, the
|
||
|
day is changed to 28.</p>
|
||
|
<p>Similarly, if a duration of months is added or subtracted, only months
|
||
|
and, if necessary, years are affected. The day portion of the date is unchanged
|
||
|
unless the result would not be valid (September 31, for example). In this
|
||
|
case, the day is set to the last day of the month.</p>
|
||
|
<p>Adding or subtracting a duration of days, of course, affects
|
||
|
the day portion of the date, and potentially the month and year.</p>
|
||
|
<p>Date durations, whether positive or negative, can also be added to and
|
||
|
subtracted from dates. As with labeled durations, the result is a valid date.</p>
|
||
|
<p>When a positive date duration is added to a date, or a negative date duration
|
||
|
is subtracted from a date, the date is incremented by the specified number
|
||
|
of years, months, and days, in that order. Thus, DATE1 + X, where X is a positive
|
||
|
DECIMAL(8,0) number, is equivalent to the expression: DATE1 + %DURYEAR(%YEAR(X))
|
||
|
+ %DURMONTH(%MONTH(X)) + %DURDAY(%DAY(X))</p>
|
||
|
<p>When a positive date duration is subtracted from a date, or a negative
|
||
|
date duration is added to a date, the date is decremented by the specified
|
||
|
number of days, months, and years, in that order. Thus, DATE1 - X, where X
|
||
|
is a positive DECIMAL(8,0) number, is equivalent to the expression: DATE1
|
||
|
- %DURDAY(%DAY(X)) - %DURMONTH(%MONTH(X)) - %DURYEAR(%YEAR(X))</p>
|
||
|
<div class="p">When adding durations to dates, adding one month to a given date gives
|
||
|
the same date one month later <em>unless</em> that date does not exist in the
|
||
|
later month. In that case, the date is set to that of the last day of the
|
||
|
later month. For example, January 28 plus one month gives February 28; and
|
||
|
one month added to January 29, 30, or 31 results in either February 28 or,
|
||
|
for a leap year, February 29. <div class="note"><span class="notetitle">Note:</span> If one or more months are added to a given
|
||
|
date and then the same number of months is subtracted from the result, the
|
||
|
final date is not necessarily the same as the original date.</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafodttaopq.htm" title="Date, time, and timestamp values can be incremented, decremented, and subtracted. These operations might involve decimal numbers called durations. These topics include a definition of durations and a specification of the rules for performing arithmetic operations on date, time, and timestamp values.">Perform date, time, and timestamp arithmetic using the Open Query File (OPNQRYF) command</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|