ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to add days in numeric date in RPG400

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to add days in numeric date in RPG400

    Hi Guys,

    can anyone please help in this..

    I have a numeric field 7,0 that is some date value.
    I need to add 30 days in the date value for my validation...

    doing this in RPGLE is easy but RPG/400 is killing me

    is there any op-code available for this..?

  • #2
    Re: How to add days in numeric date in RPG400

    hm.....use rpgle. problem solved. You can convert the source first then.....done. You should not settle for having to use rpg/400. Its way beyond its prime.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: How to add days in numeric date in RPG400

      Just write as small RPGIV Program that adds any number of days to a specified numeric date and return the result and call this program from your RPGIII program.
      An other alternative would be using embedded SQL, but SQL cannot work directly with 7 digit dates and the conversion into a real date and back is rather complex.

      Birgitta

      Comment


      • #4
        Re: How to add days in numeric date in RPG400

        What format is the 7,0 field? *cymd or *longjul or is it really a 6,0 numeric hiding in a packed field?
        what is the result field going to be....numeric/date and how big/what format?

        GLS
        Last edited by GLS400; June 19, 2014, 07:25 AM.
        The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

        Comment


        • #5
          Re: How to add days in numeric date in RPG400

          For RPG/400:

          1. Use the Convert Date and Time Format API (QWCCVTDT) to convert your date to Julian or Long Julian.
          2. Add the duration to the result.
          3. Use the API on the result to convert it to the format you need.

          Comment


          • #6
            Re: How to add days in numeric date in RPG400

            Not an op-code solution, but a 'calendar file' is/was a quite common approach to solving problems like this. Nice and low-tech too

            Comment


            • #7
              Re: How to add days in numeric date in RPG400

              Reading this thread feels like time travel back to the 1980's (or maybe early 90's), haha.

              Back when I still coded RPG/400, we used some routines that converted a date into a julian day number (not a julian date)... and that made it very easy to add/subtract dates. Clumsy by comparison to today's date operations, but worked well for 20 years ago. I'll see if I can find them somewhere...

              Comment


              • #8
                Re: How to add days in numeric date in RPG400

                Okay, here they are -- this is from the November 1988 issue of Midrange Computing, I believe -- I did not write it, please do not credit me.

                QRPGSRC member GTOJR1:
                Code:
                     C*  THIS WILL CONVERT A GREGORIAN DATE (MMDDYYYY) TO NUMBER OF
                     C*  DAYS BETWEEN TO DATES ANYWHERE FROM 03-01-1900 TO 02-28-2100
                     C*
                     C*  IN FIELD G$DW
                     C*  0=WEDNESDAY 1=THURSDAY 2=FRIDAY 3=SATURDAY 4=SUNDAY ....ETC...
                     C*
                     C*  IN FIELD G$JD    WILL HAVE A NUMBER TO USE FOR COMPARISON FOR
                     C*  THE AMOUNT OF DAYS BETWEEN TO DATES. CALL THIS PROGRAM 2 TIMES
                     C*  AND TAKE THE VALUES IT RETURNS AND SUBTRACT THEM.
                     C*                                              G$JD
                     C*  EXAMPLE::::::    01/07/91   FIRST DATE      33185
                     C*  EXAMPLE::::::    11/09/90   SECOND DATE   - 33126
                     C*  EXAMPLE::::::                              ------
                     C*  EXAMPLE::::::                                  59 DAYS OLD
                     C*
                0001 C           *ENTRY    PLIST                           PARAMETERS
                     C                     PARM           G$MM    20       MONTH(INCOMING)
                     C                     PARM           G$DD    20       DAY (INCOMING)
                     C                     PARM           G$YYYY  40       4 DIG YEAR (IN)
                     C                     PARM           G$JD    50       JULIAN DAY(OUT)
                     C*
                0002 C                     Z-ADD0         G$JD
                0003 C           G$MM      SUB  3         G$MMWK  20
                0004 C                     Z-ADDG$MMWK    GMWKSV  20
                     C*
                0005 C           G$MMWK    IFLT 0                           LVL-01
                0006 C                     ADD  12        G$MMWK
                0007 C                     END                              END-01
                     C*
                0008 C           GMWKSV    IFNE 0                           LVL-01
                0009 C           G$MMWK    MULT 30.6      G$JD      H
                0010 C                     END                              END-01
                     C*
                0011 C                     ADD  G$DD      G$JD    50
                0012 C           G$YYYY    SUB  1900      G$YYWK  30
                     C*
                0013 C           G$YYWK    IFNE 0                           LVL-01
                0014 C           GMWKSV    IFLT 0                           LVL-02
                0015 C                     SUB  1         G$YYWK
                0016 C                     END                              END-02
                0017 C                     END                              END-01
                     C*
                0018 C           G$YYWK    MULT 365.25    G$JYD   70
                0019 C                     ADD  G$JYD     G$JD
                0020 C           G$JD      DIV  7         G$WK7   70
                0021 C                     MVR            G$DW    10
                     C                     RETRN

                This is QRPGSRC member JTOGR1:
                Code:
                     C           *ENTRY    PLIST
                     C                     PARM           J$JD    50
                     C                     PARM           J$MM    20
                     C                     PARM           J$DD    20
                     C                     PARM           J$YYYY  40
                0001 C*
                0002 C           J$JD      DIV  365.25    J$YYWK  30
                0003 C           J$JD      DIV  365.25    J$TST   99
                0004 C           J$TST     IFEQ 0                           LVL-01
                0005 C                     SUB  1         J$YYWK
                0006 C                     END                              END-01
                0007 C           J$YYWK    MULT 365.25    J$YD    70
                0008 C           J$JD      SUB  J$YD      J$YD
                0009 C           J$YD      IFGT 306                         LVL-01
                0010 C                     ADD  1         J$YYWK
                0011 C                     END                              END-01
                0012 C                     Z-ADD0         J$X     20
                0013 C           J$YD      DOULEJ$MD                        LVL-01
                0014 C                     ADD  1         J$X
                0015 C           J$X       MULT 30.6      J$MD    30H
                0016 C                     END                              END-01
                0017 C                     SUB  1         J$X
                0018 C           J$X       MULT 30.6      J$MD      H
                0019 C           J$YD      SUB  J$MD      J$DD    20
                0020 C           J$X       ADD  3         J$MM    20
                0021 C           J$MM      IFGT 12                          LVL-01
                0022 C                     SUB  12        J$MM
                0023 C                     END                              END-01
                0024 C           J$YYWK    ADD  1900      J$YYYY  40
                0025 C                     SETON                     LR
                     C                     RETRN
                So to add 30 days, you would call GTOJR1 and pass your original date in the G$MM, G$DD, G$YYYY parameters. You get back the julian day number from the G$JD parameter. You can then add 30 to the value you got back in the G$JD parameter... this is now 30 days later. Then, you can call JTOGR1 and pass this new value as the J$JD parameter, and get back the new date in the J$MM, J$DD, and J$YYYY parameters.

                Ahhh, 1988... feels good to be young again.

                Comment

                Working...
                X