ibm-information-center/dist/eclipse/plugins/i5OS.ic.dbp_5.4.0.1/rbafodsubtr.htm

68 lines
4.1 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?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="Subtract dates" />
<meta name="abstract" content="The result of subtracting one date (DATE2) from another (DATE1) is a date duration that specifies the number of years, months, and days between the two dates." />
<meta name="description" content="The result of subtracting one date (DATE2) from another (DATE1) is a date duration that specifies the number of years, months, and days between the two dates." />
<meta name="DC.subject" content="arithmetic operations using OPNQRYF command, date, arithmetic using OPNQRYF command" />
<meta name="keywords" content="arithmetic operations using OPNQRYF command, date, arithmetic using OPNQRYF command" />
<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="rbafodsubtr" />
<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>Subtract dates</title>
</head>
<body id="rbafodsubtr"><a name="rbafodsubtr"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Subtract dates</h1>
<div><p>The result of subtracting one date (DATE2) from another (DATE1)
is a date duration that specifies the number of years, months, and days between
the two dates.</p>
<div class="p">The data type of the result is DECIMAL(8,0). If DATE1 is greater than or
equal to DATE2, DATE2 is subtracted from DATE1. If DATE1 is less than DATE2,
however, DATE1 is subtracted from DATE2, and the sign of the result is made
negative. The following procedural description clarifies the
steps involved in the operation RESULT = DATE1 - DATE2. <div class="fignone"><p>If %DAY(DATE2) &lt;= %DAY(DATE1) ; <br />
   then %DAY(RESULT) = %DAY(DATE1) - %DAY(DATE2).<br />
<br />
If %DAY(DATE2) &gt; %DAY(DATE1) ;<br />
   then %DAY(RESULT) = N + %DAY(DATE1) - %DAY(DATE2) ;<br />
   where N = the last day of %MONTH(DATE2). ;<br />
   %MONTH(DATE2) is then incremented by 1.<br />
<br />
If %MONTH(DATE2) &lt;= %MONTH(DATE1) ;<br />
   then %MONTH(RESULT) = %MONTH(DATE1) - %MONTH(DATE2).<br />
<br />
If %MONTH(DATE2) &gt; %MONTH(DATE1) ;<br />
   then %MONTH(RESULT) = 12 + %MONTH(DATE1) - %MONTH(DATE2). ;<br />
   %YEAR(DATE2) is then incremented by 1.<br />
<br />
%YEAR(RESULT) = %YEAR(DATE1) - %YEAR(DATE2).<br />
</p>
</div>
</div>
<p>For example, the result of %DATE('3/15/2000') - '12/31/1999' is 215 (or,
a duration of 0 years, 2 months, and 15 days).</p>
</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>