× 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 function-clarify
  • From: "Scott Klement" <infosys@xxxxxxxxxxxx>
  • Date: 13 Oct 1999 17:51:48 -0500

Hi Keshav,

The simplest answer to your question is "do the opposite of whatever
gave you the number 3457899".  None of us on this group know how you
are calculating that number, and there is more than one way to do it.

I'll attach an example program of the way that *WE* used to do
date calcs at my company when we were still restricted to RPG III.
We don't use these any more, we use the RPG IV stuff now... but the
code should still work...

I'll put the example program at the end of this message. Have fun.

"keshava narasimha" <anandthirta@hotmail.com> wrote:
> Hi !
>
> Let me be more clear on my question first...
>
> I have a date  1999/12/12 o.k..When I convert this date into days I
>  you get a figure. (like 3457899)
>
> Now if  need to display tomorrows date ,  I add 1 to this number and
>  how do I display 1999/12/13 is the Question?(the function needs to
>  be done using RPG/400 only not ILERPG)
>
> Thanks for all  your time.
>
> Keshav


C* FOR THE SAKE OF THIS EXAMPLE, ASSUME THAT *DATE IS
C*     IN MMDDYYYY (USA) FORMAT...
C*
C*****************************************************
C* EXAMPLE OF CALCULATING TOMORROWS DATE:
C*****************************************************
C                     MOVE *DATE     G$YYYY
C                     MOVEL*DATE     LEFT4   4
C                     MOVELLEFT4     G$MM
C                     MOVE LEFT4     G$DD
C                     EXSR GTOD
C*
C*  ADD 1 TO MAKE IT TOMORROW'S DATE:
C           G$JD      ADD  1         J$JD
C*
C*  CONVERT BACK TO MMDDYYYY FORMAT
C                     EXSR DTOG
C                     MOVE J$YYYY    MYDATE  80
C                     MOVELJ$MM      LEFT4
C                     MOVE J$DD      LEFT4
C                     MOVELLEFT4     MYDATE
C*
C*  SHOW THE DATE:
C           MYDATE    DSPLY          WAIT    1
C*
C*****************************************************
C*  EXAMPLE OF GETTING THE DAY OF THE WEEK:
C*****************************************************
C                     MOVE MYDATE    G$YYYY
C                     MOVELMYDATE    LEFT4   4
C                     MOVELLEFT4     G$MM
C                     MOVE LEFT4     G$DD
C                     EXSR GTOD
C*
C                     SELEC
C           G$DW      WHEQ 0
C                     MOVEL'WED'     DOW     3
C           G$DW      WHEQ 1
C                     MOVEL'THU'     DOW
C           G$DW      WHEQ 2
C                     MOVEL'FRI'     DOW
C           G$DW      WHEQ 3
C                     MOVEL'SAT'     DOW
C           G$DW      WHEQ 4
C                     MOVEL'SUN'     DOW
C           G$DW      WHEQ 5
C                     MOVEL'MON'     DOW
C           G$DW      WHEQ 6
C                     MOVEL'TUE'     DOW
C                     OTHER
C                     MOVEL'ERR'     DOW
C                     ENDSL
C*
C           DOW       DSPLY          WAIT
C*
C*****************************************************
C*  EXAMPLE OF VERIFYING THAT A DATE IS VALID:
C*****************************************************
C* GOOD DATE
C                     MOVE '01011999'MYDATE
C                     EXSR CHKDAT
C* GOOD DATE
C                     MOVE '02292000'MYDATE
C                     EXSR CHKDAT
C* BAD DATE
C                     MOVE '09312004'MYDATE
C                     EXSR CHKDAT
C* BAD DATE
C                     MOVE '02291999'MYDATE
C                     EXSR CHKDAT
 *
 *
C                     MOVE *ON       *INLR
 *
 *
C*====================================================
C* CHECK A DATE TO SEE IF ITS VALID
C*
C*  INPUT:  MYDATE (8,0)  DATE IN MMDDYYYY FORMAT.
C*
C* OUTPUT:  "GOOD" OR "BAD" IS DSPLY-ED
C*            ON THE SCREEN.
C*====================================================
CSR         CHKDAT    BEGSR
C*-------------------------
C                     MOVE MYDATE    G$YYYY
C                     MOVELMYDATE    LEFT4   4
C                     MOVELLEFT4     G$MM
C                     MOVE LEFT4     G$DD
C                     EXSR GTOD
C                     MOVE G$JD      J$JD
C                     EXSR DTOG
C*
C           J$MM      IFEQ G$MM
C           J$DD      ANDEQG$DD
C           J$YYYY    ANDEQG$YYYY
C           'GOOD'    DSPLY          WAIT    1
C                     ELSE
C           'BAD '    DSPLY          WAIT    1
C                     ENDIF
C*-------------------------
CSR                   ENDSR
 *
 *
 *
C*====================================================
C* GREGORIAN TO DAY NUMBER:
C*
C*    INPUT: G$MM (2,0)      OUTPUT: G$JD (5,0)
C*           G$DD (2,0)              G$DW (1,0)
C*           G$YYYY (4,0)
C*
C* DATES NEED TO BE IN THE RANGE 03-01-1900 TO 02-28-2100
C*
C* G$DW CONTAINS: 0=WED, 1=THU, 2=FRI, 3=SAT, 4=SUN, 5=MON, 6=TUE
C*====================================================
CSR         GTOD      BEGSR
C*-------------------------
C           *LIKE     DEFN J$MM      G$MM
C           *LIKE     DEFN J$DD      G$DD
C           *LIKE     DEFN J$YYYY    G$YYYY
C*
C                     Z-ADD0         G$JD    50
C           G$MM      SUB  3         G$MMWK  20
C                     Z-ADDG$MMWK    GMWKSV  20
C*
C           G$MMWK    IFLT 0                           LVL-01
C                     ADD  12        G$MMWK
C                     END                              END-01
C*
C           GMWKSV    IFNE 0                           LVL-01
C           G$MMWK    MULT 30.6      G$JD      H
C                     END                              END-01
C*
C                     ADD  G$DD      G$JD    50
C           G$YYYY    SUB  1900      G$YYWK  30
C*
C           G$YYWK    IFNE 0                           LVL-01
C           GMWKSV    IFLT 0                           LVL-02
C                     SUB  1         G$YYWK
C                     END                              END-02
C                     END                              END-01
C*
C           G$YYWK    MULT 365.25    G$JYD   70
C                     ADD  G$JYD     G$JD
C           G$JD      DIV  7         G$WK7   70
C                     MVR            G$DW    10
C*-------------------------
CSR                   ENDSR
 *
 *
 *
C*====================================================
C*  DAY NUMBER TO GREGORIAN:
C*
C*     THIS CONVERTS FROM THE DAY NUMBER (LIKE ABOVE)
C*     INTO A GREGORIAN DATE.
C*
C*    INPUT: J$JD        OUTPUT: J$MM
C*                               J$DD
C*                               J$YYYY
C*
C* DATES NEED TO BE IN THE RANGE 03-01-1900 TO 02-28-2100
C*====================================================
CSR         DTOG      BEGSR
C*-------------------------
C           *LIKE     DEFN G$JD      J$JD
C*
C           J$JD      DIV  365.25    J$YYWK  30
C           J$JD      DIV  365.25    J$TST   99
C           J$TST     IFEQ 0                           LVL-01
C                     SUB  1         J$YYWK
C                     END                              END-01
C           J$YYWK    MULT 365.25    J$YD    70
C           J$JD      SUB  J$YD      J$YD
C           J$YD      IFGT 306                         LVL-01
C                     ADD  1         J$YYWK
C                     END                              END-01
C                     Z-ADD0         J$X     20
C           J$YD      DOULEJ$MD                        LVL-01
C                     ADD  1         J$X
C           J$X       MULT 30.6      J$MD    30H
C                     END                              END-01
C                     SUB  1         J$X
C           J$X       MULT 30.6      J$MD      H
C           J$YD      SUB  J$MD      J$DD    20
C           J$X       ADD  3         J$MM    20
C           J$MM      IFGT 12                          LVL-01
C                     SUB  12        J$MM
C                     END                              END-01
C           J$YYWK    ADD  1900      J$YYYY  40
C*-------------------------
CSR                   ENDSR
+---
| 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 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.