× 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: Dates
  • From: Billy Rowe <billyrowe@xxxxxxx>
  • Date: Fri, 19 Nov 1999 18:58:51 -0500

Jim Langston wrote:
> 
> I have a file with dates stored in a numeric MMDDYY format.  I convert
> them to dates using the following:
> 
> D                             DS
> D RealDate                1  10D        DATFMT(*ISO)
> D  RealDateCC         1    2S 0
> D  RealDateYY         3    4S 0
> D  RealDateMM        6   7S 0
> D  RealDateDD          9 10S 0
> D YMDDate             11 16S 0
> D   YMDDateYY      11 12S 0
> D MDYDate             13 18S 0
> D   MDYDateYY      17 18S 0
> D DateMM                13 14S 0
> D DateDD                  15 16S 0
> 
> C          Eval  MDYDate = FEDEta
> C          Exsr  MDYDateToDate
> 
> the Sub MDYDateToDate just does a bunch of moving around of values,
> comparing
> MDYDateYY to 99, if it's 99 it sets RealDateCC to 19, otherwise sets to
> 20, then
> it moves the YY MM and DD fields to the Date field, then I have a date
> fields.
> 
> Is there an easier way?  There MUST be!


d MDYdateWrk      s               D   DATFMT(*ISO) INZ

You can use the MOVE statement to automatically convert between
different
date formats, the following line converts a MMDDYY date to the ISO
format. 

C     *mdy          move      MMDDYY        MDYdateWrk

Look at the MOVE calc in the RPG ILE manual for handling dates.

The following are some examples for creating date data type fields from
existing fields:

D                 DS                                        
 * Todays date                                              
D Today                           D   DATFMT(*ISO) INZ      
D  TodayYear                     4    OVERLAY(Today)        
D  TodayMonth                    2    OVERLAY(Today:6)      
D  TodayDay                      2    OVERLAY(Today:9)      
                                                            
D                 DS                                        
 * isconnect date                                      
D DscConDate                      D   DATFMT(*YMD) INZ      
D  DscConYY                      2    OVERLAY(DscConDate)   
D  DscConMM                      2    OVERLAY(DscConDate:4) 
D  DscConDD                      2    OVERLAY(DscConDate:7) 

You could then also determine the number of days between these 2 dates
as follows:

C     Today         SubDur    DscConDate    HdAge:*D

> 
> Also, later on I attempted to do a comparison,
> 
> C              If      RealDate < '1999-11-01'
> 
> but received an error, incompatable types.  so I then copied the
> RealDate to
> a date varialbe, and did the whole rigamarole in converting 110199 to
> RealDate,
> then could do the comparison between dates.
> 
> Again, there MUST be an easier way!
> 
> How do you hard code a date so that RPG recognizes it as a date?


Look at the above examples.


Hope this helps,


Billy

+---
| 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 ...

Follow-Ups:
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.