× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: Date calculations
  • From: "Gary R. Patterson" <rpg400-l@xxxxxxxxxxxxx>
  • Date: Thu, 31 Aug 2000 21:52:19 -0500
  • Importance: Normal

Rather than using Julians, use RPG IV date fields.  Julians get a little
hairy if you cross the end of the year.  In RPG IV, SUBDUR subtracts two
date fields.  The trick is to get the numerics converted into date fields.

You can also use ILE date APIs, but this is a little simpler.

 * Create two numeric dates, and two date fields
D shipDate        s              8P 0 inz(20000808)
D reqDelivDate    s              8p 0 inz(20000804)
D DshipDate       s               d
d DreqDelivDate   s               d

 * This will hold the difference
d daysBetween     s              5p 0

 * Logical variable - error flag
d problem         s               n

 * Test to make sure they are valid dates in ISO format
 * *ISO = yyyy-mm-dd.  Separators do not apply since field
 * is numeric.
c                   eval      problem = *off
c     *iso          test(d e)               shipDate
c                   if        %error
c                   eval      problem = *on
c                   else
c     *iso          test(d e)               reqDelivDate
c                   if        %error
c                   eval      problem = *on
c                   endif
c                   endif

 *                  ... If no problems, convert numeric
 *                      to date fields, specifying numeric format
 *                      as ISO
c                   if        not problem
 ********           ...   or (problem = *off), if you prefer
c     *iso          move      shipDate      DshipDate
c     *iso          move      reqDelivDate  DreqDelivDate

 *                  ...Subtract dates, storing results
 *                     in days (*D) in numeric variable
 *                     NOTE: If dSHIPDATE is more recent than
 *                     dREQDELIVDATE, daysBetween will be negative.
 *                     You can use the absolute value function to
 *                     fix that:  eval daysLate = %abs(daysBetween)
c     dReqDelivDate subdur    dShipDate     daysBetween:*D

c                   else
 *                  ... handle error
c                   endif

C                   eval      *inlr = *on

Gary R. Patterson
NexSource, Inc.

980 N Michigan Ave, Suite 1400
Chicago, IL 60611
(312) 214-3526

640 W. Main St.
Louisville, KY 40202
(502) 581-0106

Information technology services for business
http://www.nexsource.com



-----Original Message-----
From: owner-rpg400-l@midrange.com [mailto:owner-rpg400-l@midrange.com]On
Behalf Of Kathy Wyatt
Sent: Thursday, August 31, 2000 7:22 PM
To: RPG400-L@midrange.com
Subject: Date caclulations


This is a newbie questions so please take it easy on me, everyone has to
start somewhere. I have no manuals available to me (offline), just text
books which yielded no suggestions.

I need to know if it is possible to subtract two dates (which will be
retrieved from an input file as numeric 8 digit fields (yyyymmdd)) and get a
numeric answer.  For instance, input fields with numeric values -
ShipDate = 20000808 and ReqDelivDate = 20000804, I would like to have 4 as
my result.

I think it can be done with julian dates somehow but I do not know how to
convert a numeric field to a julian date field.

Your assistance is greatly appreciated.

Kat W

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator:
david@midrange.com
+---

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.