 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Subtracting Date/Time AS400 V5R4</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/subtracting-datetime-as400-v5r4/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/subtracting-datetime-as400-v5r4/</link>
	<description></description>
	<lastBuildDate>Sun, 19 May 2013 03:14:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: tomliotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/subtracting-datetime-as400-v5r4/#comment-81309</link>
		<dc:creator>tomliotta</dc:creator>
		<pubDate>Wed, 08 Sep 2010 21:41:23 +0000</pubDate>
		<guid isPermaLink="false">#comment-81309</guid>
		<description><![CDATA[&lt;i&gt;There is a built in function that you can use called %DIFF&lt;/i&gt;

In ILE RPG, that is correct. A couple points in the manual can tend to be misleading, but it&#039;s a very useful %bif:&lt;pre&gt;
     H Debug
     D TstNum          s              7  0 inz( 0 )

     D t1              s               z   inz( *sys )
     D t2              s               z   inz( *sys )

     C                   seton                                        LR

     c                   eval      t2 -= %days( 2 )
     c                   eval      t2 -= %minutes( 10 )
     c                   eval      TstNum = %diff( t1 : t2 : *minutes )

     C                   dump&lt;/pre&gt;
The two timestamp fields are both initialized to the system date. Then two days are subtracted from t2 and 10 minutes are also subtracted from t2. That should make the total difference between the two timestamps as being 2 days and 10 minutes.

The result of the %diff() is 2890 minutes. With 1440 minutes in a day, it&#039;s right on.

Tom]]></description>
		<content:encoded><![CDATA[<p><i>There is a built in function that you can use called %DIFF</i></p>
<p>In ILE RPG, that is correct. A couple points in the manual can tend to be misleading, but it&#8217;s a very useful %bif:
<pre>
     H Debug
     D TstNum          s              7  0 inz( 0 )

     D t1              s               z   inz( *sys )
     D t2              s               z   inz( *sys )

     C                   seton                                        LR

     c                   eval      t2 -= %days( 2 )
     c                   eval      t2 -= %minutes( 10 )
     c                   eval      TstNum = %diff( t1 : t2 : *minutes )

     C                   dump</pre>
<p>The two timestamp fields are both initialized to the system date. Then two days are subtracted from t2 and 10 minutes are also subtracted from t2. That should make the total difference between the two timestamps as being 2 days and 10 minutes.</p>
<p>The result of the %diff() is 2890 minutes. With 1440 minutes in a day, it&#8217;s right on.</p>
<p>Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shatteredraven77</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/subtracting-datetime-as400-v5r4/#comment-81293</link>
		<dc:creator>shatteredraven77</dc:creator>
		<pubDate>Wed, 08 Sep 2010 14:45:26 +0000</pubDate>
		<guid isPermaLink="false">#comment-81293</guid>
		<description><![CDATA[There is a built in function that you can use called &lt;b&gt;%DIFF&lt;/b&gt; 

d DiffInDays      s              4s 0 inz   
d DiffInHours     s              4s 0 inz   
d DiffInMonths    s              4s 0 inz   
d DiffInYears     s              4s 0 inz   
d FromDateInISO   s               d   inz   
d ToDateInISO     s               d   inz 

eval      DiffInDays    = %Diff(FromDateInISO:ToDateInISO:*DAYS)  
eval      DiffInMonths  = %Diff(FromDateInISO:ToDateInISO:*MONTHS)
eval      DiffInYears   = %Diff(FromDateInISO:ToDateInISO:*YEARS) 

You would probably have to do some funky calculations, but this built in function works pretty nicely.  You can also use it with timestamps also.

The &lt;i&gt;IBM WebSphere Development Studio ILE RPG Language Reference Version 5&lt;/i&gt; manual (SC09-2508-06) has this built in function on PDF page 525 and 526. The URL to that manual is:

http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/books/sc092508.pdf

Hope this helps!]]></description>
		<content:encoded><![CDATA[<p>There is a built in function that you can use called <b>%DIFF</b> </p>
<p>d DiffInDays      s              4s 0 inz<br />
d DiffInHours     s              4s 0 inz<br />
d DiffInMonths    s              4s 0 inz<br />
d DiffInYears     s              4s 0 inz<br />
d FromDateInISO   s               d   inz<br />
d ToDateInISO     s               d   inz </p>
<p>eval      DiffInDays    = %Diff(FromDateInISO:ToDateInISO:*DAYS)<br />
eval      DiffInMonths  = %Diff(FromDateInISO:ToDateInISO:*MONTHS)<br />
eval      DiffInYears   = %Diff(FromDateInISO:ToDateInISO:*YEARS) </p>
<p>You would probably have to do some funky calculations, but this built in function works pretty nicely.  You can also use it with timestamps also.</p>
<p>The <i>IBM WebSphere Development Studio ILE RPG Language Reference Version 5</i> manual (SC09-2508-06) has this built in function on PDF page 525 and 526. The URL to that manual is:</p>
<p><a href="http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/books/sc092508.pdf" rel="nofollow">http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/books/sc092508.pdf</a></p>
<p>Hope this helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tomliotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/subtracting-datetime-as400-v5r4/#comment-80095</link>
		<dc:creator>tomliotta</dc:creator>
		<pubDate>Mon, 09 Aug 2010 01:06:09 +0000</pubDate>
		<guid isPermaLink="false">#comment-80095</guid>
		<description><![CDATA[I recalled seeing a way to handle Float8 values in ILE CL, but didn&#039;t have reference handy at the time I posted the earlier example. I did a search last night and ran across an article by former IBMer Bruce Vining who demonstrated &lt;a href=&quot;http://www.mcpressonline.com/programming/cl/the-cl-corner-more-on-ile-cee-time-apis.html&quot;&gt;using the _LBCPYNV builtin API&lt;/a&gt;.

The builtin isn&#039;t fully described in the article, but the usage may be enough to compare against &lt;a href=&quot;http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/rzatk/CPYNV.htm&quot;&gt;the documentation&lt;/a&gt; to learn most ways to use it. New questions can be asked if necessary.

Here it&#039;s used to convert the Float8 into a *DEC (15 0) without first creating an additional external proc in a different language. This allows everything to be done in ILE CL.

The CL below does what the previous one does in terms of results. It uses the same &#039;current&#039; timestamp value and the same five sample past dates. The decimal seconds value has been slightly changed to make it an integer value, to accommodate the straight conversion. The &#039;number of seconds&#039; value is going to be an integer value anyway.

The CEESECS and _LBCPYNV APIs might be put into a proc that accepts a date or two, and possibly a format (or two), and returns a difference.
&lt;pre&gt;
pgm    ( +
       )

   dcl   &amp;FirstDate     *char       26     value( &#039;2010-08-04-14.20.29.073376&#039; )
   dcl   &amp;SecndDate     *char       26     value( &#039;2010-08-04-16.46.04.073376&#039; )
   dcl   &amp;ThirdDate     *char       26     value( &#039;2010-08-05-14.20.29.073376&#039; )
   dcl   &amp;ForthDate     *char       26     value( &#039;2010-08-05-16.40.29.073376&#039; )
   dcl   &amp;FifthDate     *char       11     value( &#039;Aug 05 2010&#039; )

   dcl   &amp;NowDate       *char       26     value( &#039;2010-08-05-16.46.04.073376&#039; )

   dcl   &amp;PicStr        *char       26     value( &#039;YYYY-MM-DD-HH.MI.SS.999999&#039; )

   dcl   &amp;RtnVal1       *char        8
   dcl   &amp;RtnVal2       *char        8

   dcl   &amp;NowSecs       *dec      ( 15 0 ) value( 0 )
   dcl   &amp;PastSecs      *dec      ( 15 0 ) value( 0 )

   dcl   &amp;NbrSecs       *dec      ( 15 0 ) value( 0 )
   dcl   &amp;NbrMins       *dec      ( 15 3 ) value( 0 )
   dcl   &amp;NbrHrs        *dec      ( 15 3 ) value( 0 )

   dcl   &amp;Flt_Dfn       *char        7     value( x&#039;01000800000000&#039; )
   dcl   &amp;Dec_Dfn       *char        7     value( x&#039;03000F00000000&#039; )


/* Get NumberOfSeconds for our &quot;Now&quot; date to use later... */
   callprc      CEESECS      ( +
                               &amp;NowDate       +
                               &amp;PicStr        +
                               &amp;RtnVal1       +
                               *omit          +
                             )

/* ...and turn Float8 into *DEC (15 0)... */
   callprc      &#039;_LBCPYNV&#039;   ( +
                               &amp;NowSecs       +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal1       +
                               &amp;Flt_Dfn       +
                             )

/* Get NumberOfSeconds for our First test date... */
   callprc      CEESECS      ( +
                               &amp;FirstDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      &#039;_LBCPYNV&#039;   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between &quot;Now&quot; and our first past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

/* ...and also convert to both minutes and hours... */
   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

/* Get NumberOfSeconds for our Second test date... */
   callprc      CEESECS      ( +
                               &amp;SecndDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      &#039;_LBCPYNV&#039;   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between &quot;Now&quot; and our second past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

/* Get NumberOfSeconds for our Third test date... */
   callprc      CEESECS      ( +
                               &amp;ThirdDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      &#039;_LBCPYNV&#039;   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between &quot;Now&quot; and our third past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

/* Get NumberOfSeconds for our Fourth test date... */
   callprc      CEESECS      ( +
                               &amp;ForthDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      &#039;_LBCPYNV&#039;   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between &quot;Now&quot; and our fourth past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

/* Get NumberOfSeconds for our Fifth test date... */
   callprc      CEESECS      ( +
                               &amp;FifthDate     +
                               &#039;Mmm DD YYYY&#039;  +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      &#039;_LBCPYNV&#039;   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between &quot;Now&quot; and our fifth past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   return

endpgm&lt;/pre&gt;
In its simplest form, compile it as a module named SUBDURHMS and create the program as:&lt;pre&gt;
CRTPGM PGM( SUBDURHMS )
       BNDDIR(QC2LE)&lt;/pre&gt;
Name it however you choose and specify other parms as desired.

Tom]]></description>
		<content:encoded><![CDATA[<p>I recalled seeing a way to handle Float8 values in ILE CL, but didn&#8217;t have reference handy at the time I posted the earlier example. I did a search last night and ran across an article by former IBMer Bruce Vining who demonstrated <a href="http://www.mcpressonline.com/programming/cl/the-cl-corner-more-on-ile-cee-time-apis.html">using the _LBCPYNV builtin API</a>.</p>
<p>The builtin isn&#8217;t fully described in the article, but the usage may be enough to compare against <a href="http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/rzatk/CPYNV.htm">the documentation</a> to learn most ways to use it. New questions can be asked if necessary.</p>
<p>Here it&#8217;s used to convert the Float8 into a *DEC (15 0) without first creating an additional external proc in a different language. This allows everything to be done in ILE CL.</p>
<p>The CL below does what the previous one does in terms of results. It uses the same &#8216;current&#8217; timestamp value and the same five sample past dates. The decimal seconds value has been slightly changed to make it an integer value, to accommodate the straight conversion. The &#8216;number of seconds&#8217; value is going to be an integer value anyway.</p>
<p>The CEESECS and _LBCPYNV APIs might be put into a proc that accepts a date or two, and possibly a format (or two), and returns a difference.</p>
<pre>
pgm    ( +
       )

   dcl   &amp;FirstDate     *char       26     value( '2010-08-04-14.20.29.073376' )
   dcl   &amp;SecndDate     *char       26     value( '2010-08-04-16.46.04.073376' )
   dcl   &amp;ThirdDate     *char       26     value( '2010-08-05-14.20.29.073376' )
   dcl   &amp;ForthDate     *char       26     value( '2010-08-05-16.40.29.073376' )
   dcl   &amp;FifthDate     *char       11     value( 'Aug 05 2010' )

   dcl   &amp;NowDate       *char       26     value( '2010-08-05-16.46.04.073376' )

   dcl   &amp;PicStr        *char       26     value( 'YYYY-MM-DD-HH.MI.SS.999999' )

   dcl   &amp;RtnVal1       *char        8
   dcl   &amp;RtnVal2       *char        8

   dcl   &amp;NowSecs       *dec      ( 15 0 ) value( 0 )
   dcl   &amp;PastSecs      *dec      ( 15 0 ) value( 0 )

   dcl   &amp;NbrSecs       *dec      ( 15 0 ) value( 0 )
   dcl   &amp;NbrMins       *dec      ( 15 3 ) value( 0 )
   dcl   &amp;NbrHrs        *dec      ( 15 3 ) value( 0 )

   dcl   &amp;Flt_Dfn       *char        7     value( x'01000800000000' )
   dcl   &amp;Dec_Dfn       *char        7     value( x'03000F00000000' )


/* Get NumberOfSeconds for our "Now" date to use later... */
   callprc      CEESECS      ( +
                               &amp;NowDate       +
                               &amp;PicStr        +
                               &amp;RtnVal1       +
                               *omit          +
                             )

/* ...and turn Float8 into *DEC (15 0)... */
   callprc      '_LBCPYNV'   ( +
                               &amp;NowSecs       +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal1       +
                               &amp;Flt_Dfn       +
                             )

/* Get NumberOfSeconds for our First test date... */
   callprc      CEESECS      ( +
                               &amp;FirstDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      '_LBCPYNV'   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between "Now" and our first past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

/* ...and also convert to both minutes and hours... */
   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

/* Get NumberOfSeconds for our Second test date... */
   callprc      CEESECS      ( +
                               &amp;SecndDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      '_LBCPYNV'   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between "Now" and our second past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

/* Get NumberOfSeconds for our Third test date... */
   callprc      CEESECS      ( +
                               &amp;ThirdDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      '_LBCPYNV'   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between "Now" and our third past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

/* Get NumberOfSeconds for our Fourth test date... */
   callprc      CEESECS      ( +
                               &amp;ForthDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      '_LBCPYNV'   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between "Now" and our fourth past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

/* Get NumberOfSeconds for our Fifth test date... */
   callprc      CEESECS      ( +
                               &amp;FifthDate     +
                               'Mmm DD YYYY'  +
                               &amp;RtnVal2       +
                               *omit          +
                             )
   callprc      '_LBCPYNV'   ( +
                               &amp;PastSecs      +
                               &amp;Dec_Dfn       +
                               &amp;RtnVal2       +
                               &amp;Flt_Dfn       +
                             )

/* Get difference between "Now" and our fifth past date... */
   chgvar       &amp;NbrSecs     ( &amp;NowSecs - &amp;PastSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   return

endpgm</pre>
<p>In its simplest form, compile it as a module named SUBDURHMS and create the program as:
<pre>
CRTPGM PGM( SUBDURHMS )
       BNDDIR(QC2LE)</pre>
<p>Name it however you choose and specify other parms as desired.</p>
<p>Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tomliotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/subtracting-datetime-as400-v5r4/#comment-80041</link>
		<dc:creator>tomliotta</dc:creator>
		<pubDate>Fri, 06 Aug 2010 02:20:26 +0000</pubDate>
		<guid isPermaLink="false">#comment-80041</guid>
		<description><![CDATA[&lt;i&gt;...how to write it in a CL program.&lt;/i&gt;

I apologize -- I assumed you meant RPG after you mentioned SUBDUR.

Although the CEESECS API can be called successfully with ILE CL, the seconds value is only useful for passing into other APIs. If you need to do arithmetic operations on the value, you need to pass it to a language that can handle 8-byte floating point variables. RPG can do it.

In case it&#039;s useful for you, here&#039;s a minimal RPG proc that subtracts a float-8 from another float-8 and returns a packed (15,3):&lt;pre&gt;
     H NoMain

     D SubFlt8         pr            15p 3 extproc( &#039;SUBFLT8&#039; )
     D flt8_1                         8f   const
     D flt8_2                         8f   const

     p SubFlt8         b                   export

     D SubFlt8         pi            15p 3
     D flt8_1                         8f   const
     D flt8_2                         8f   const

     C                   return    ( flt8_1 - flt8_2 )

     p SubFlt8         e&lt;/pre&gt;
This ILE CL module calls that proc a few times in order to show a few hours, minutes and seconds differences between some different timestamps:&lt;pre&gt;
pgm    ( +
       )

   dcl   &amp;FirstDate     *char       26     value( &#039;2010-08-04-14.20.29.073376&#039; )
   dcl   &amp;SecndDate     *char       26     value( &#039;2010-08-04-16.46.04.073376&#039; )
   dcl   &amp;ThirdDate     *char       26     value( &#039;2010-08-05-14.20.29.073376&#039; )
   dcl   &amp;ForthDate     *char       26     value( &#039;2010-08-05-16.40.29.073376&#039; )
   dcl   &amp;FifthDate     *char       11     value( &#039;Aug 05 2010&#039; )

   dcl   &amp;NowDate       *char       26     value( &#039;2010-08-05-16.46.04.073376&#039; )

   dcl   &amp;PicStr        *char       26     value( &#039;YYYY-MM-DD-HH.MI.SS.999999&#039; )

   dcl   &amp;RtnVal1       *char        8
   dcl   &amp;RtnVal2       *char        8

   dcl   &amp;NbrSecs       *dec      ( 15 3 ) value( 0 )
   dcl   &amp;NbrMins       *dec      ( 15 3 ) value( 0 )
   dcl   &amp;NbrHrs        *dec      ( 15 3 ) value( 0 )


   callprc      CEESECS      ( +
                               &amp;NowDate       +
                               &amp;PicStr        +
                               &amp;RtnVal1       +
                               *omit          +
                             )


   callprc      CEESECS      ( +
                               &amp;FirstDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   callprc      CEESECS      ( +
                               &amp;SecndDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   callprc      CEESECS      ( +
                               &amp;ThirdDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   callprc      CEESECS      ( +
                               &amp;ForthDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   callprc      CEESECS      ( +
                               &amp;FifthDate     +
                               &#039;Mmm DD YYYY&#039;  +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   return

endpgm&lt;/pre&gt;
There are five different date/time values at the top, followed by a &amp;NowDate value. Each of the first five date/times are subtracted from &amp;NowDate in turn. The resulting hours/minutes/seconds are shown in the dumps that happen after each round.

You&#039;ll quickly see the &amp;FifthDate is very different from all of the others.

Some of this code comes from a basic test procedure that I had handy. It was using a date/time value that was formatted as a timestamp, so the &quot;picture string&quot; variable was set up for a timestamp. I duplicated the values and made minor changes in order to show how the number of seconds between each date and &amp;NowDate really did come out correct.

But I put &amp;FifthDate into this example to show how date/time string values can be described through the &quot;picture string&quot; variable value. As I said earlier, there is a lot of flexibility. For this one, I used a constant picture string and I let the time portion go as a default. The dumps will show enough to figure out what the defaults are.

Note that instead of using a constant for the &amp;NowDate value, I could have simply retrieved the QDATETIME system value and created an appropriate picture string as the program ran.

Sorry about not thinking of CL at the start. I just didn&#039;t see a mention of it. Otherwise I might not have said anything.

Tom]]></description>
		<content:encoded><![CDATA[<p><i>&#8230;how to write it in a CL program.</i></p>
<p>I apologize &#8212; I assumed you meant RPG after you mentioned SUBDUR.</p>
<p>Although the CEESECS API can be called successfully with ILE CL, the seconds value is only useful for passing into other APIs. If you need to do arithmetic operations on the value, you need to pass it to a language that can handle 8-byte floating point variables. RPG can do it.</p>
<p>In case it&#8217;s useful for you, here&#8217;s a minimal RPG proc that subtracts a float-8 from another float-8 and returns a packed (15,3):
<pre>
     H NoMain

     D SubFlt8         pr            15p 3 extproc( 'SUBFLT8' )
     D flt8_1                         8f   const
     D flt8_2                         8f   const

     p SubFlt8         b                   export

     D SubFlt8         pi            15p 3
     D flt8_1                         8f   const
     D flt8_2                         8f   const

     C                   return    ( flt8_1 - flt8_2 )

     p SubFlt8         e</pre>
<p>This ILE CL module calls that proc a few times in order to show a few hours, minutes and seconds differences between some different timestamps:
<pre>
pgm    ( +
       )

   dcl   &amp;FirstDate     *char       26     value( '2010-08-04-14.20.29.073376' )
   dcl   &amp;SecndDate     *char       26     value( '2010-08-04-16.46.04.073376' )
   dcl   &amp;ThirdDate     *char       26     value( '2010-08-05-14.20.29.073376' )
   dcl   &amp;ForthDate     *char       26     value( '2010-08-05-16.40.29.073376' )
   dcl   &amp;FifthDate     *char       11     value( 'Aug 05 2010' )

   dcl   &amp;NowDate       *char       26     value( '2010-08-05-16.46.04.073376' )

   dcl   &amp;PicStr        *char       26     value( 'YYYY-MM-DD-HH.MI.SS.999999' )

   dcl   &amp;RtnVal1       *char        8
   dcl   &amp;RtnVal2       *char        8

   dcl   &amp;NbrSecs       *dec      ( 15 3 ) value( 0 )
   dcl   &amp;NbrMins       *dec      ( 15 3 ) value( 0 )
   dcl   &amp;NbrHrs        *dec      ( 15 3 ) value( 0 )


   callprc      CEESECS      ( +
                               &amp;NowDate       +
                               &amp;PicStr        +
                               &amp;RtnVal1       +
                               *omit          +
                             )


   callprc      CEESECS      ( +
                               &amp;FirstDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   callprc      CEESECS      ( +
                               &amp;SecndDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   callprc      CEESECS      ( +
                               &amp;ThirdDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   callprc      CEESECS      ( +
                               &amp;ForthDate     +
                               &amp;PicStr        +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   callprc      CEESECS      ( +
                               &amp;FifthDate     +
                               'Mmm DD YYYY'  +
                               &amp;RtnVal2       +
                               *omit          +
                             )

   callprc      SUBFLT8      ( +
                               &amp;RtnVal1       +
                               &amp;RtnVal2       +
                             ) +
                       rtnval( &amp;NbrSecs )

   chgvar       &amp;NbrMins     ( &amp;NbrSecs / 60 )
   chgvar       &amp;NbrHrs      ( &amp;NbrSecs / ( 60 * 60 ) )

dmpclpgm

   return

endpgm</pre>
<p>There are five different date/time values at the top, followed by a &amp;NowDate value. Each of the first five date/times are subtracted from &amp;NowDate in turn. The resulting hours/minutes/seconds are shown in the dumps that happen after each round.</p>
<p>You&#8217;ll quickly see the &amp;FifthDate is very different from all of the others.</p>
<p>Some of this code comes from a basic test procedure that I had handy. It was using a date/time value that was formatted as a timestamp, so the &#8220;picture string&#8221; variable was set up for a timestamp. I duplicated the values and made minor changes in order to show how the number of seconds between each date and &amp;NowDate really did come out correct.</p>
<p>But I put &amp;FifthDate into this example to show how date/time string values can be described through the &#8220;picture string&#8221; variable value. As I said earlier, there is a lot of flexibility. For this one, I used a constant picture string and I let the time portion go as a default. The dumps will show enough to figure out what the defaults are.</p>
<p>Note that instead of using a constant for the &amp;NowDate value, I could have simply retrieved the QDATETIME system value and created an appropriate picture string as the program ran.</p>
<p>Sorry about not thinking of CL at the start. I just didn&#8217;t see a mention of it. Otherwise I might not have said anything.</p>
<p>Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ghender</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/subtracting-datetime-as400-v5r4/#comment-80036</link>
		<dc:creator>ghender</dc:creator>
		<pubDate>Thu, 05 Aug 2010 20:22:57 +0000</pubDate>
		<guid isPermaLink="false">#comment-80036</guid>
		<description><![CDATA[Do you have an example of how to use this API? I looked at the link you included and I can see how to call it manually but I can&#039;t figure out how to write it in a CL program.]]></description>
		<content:encoded><![CDATA[<p>Do you have an example of how to use this API? I looked at the link you included and I can see how to call it manually but I can&#8217;t figure out how to write it in a CL program.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.049 seconds using memcached
Object Caching 323/329 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-19 12:16:41 -->