MIDRANGE dot COM Mailing List Archive



Home » RPG400-L » January 2000

Re: doing date arithmetic in CL



fixed

Rick,

There is a TAATOOL called ADDDAT that will allow you to add number of days to a 
date.  This is great command for doing what you are wanting.

In the absence of this command, the following is some CL code that will allow 
you to add dates.  The code is provided "as-is".  You will need to ensure that 
it is appropriate for your environment.

With this program, you would pass the beginning date and the number of days you 
want to add (the number can be a negative).  The program will return the end 
date.


PGM           PARM(&begdate                           +
                   &days                              +
                   &enddate  )

   DCL        VAR(&begdate   )                        + 
              TYPE(*CHAR     )                        + 
              LEN(6          )                          
   DCL        VAR(&day       )                        + 
              TYPE(*CHAR     )                        + 
              LEN(2          )                          
   DCL        VAR(&days      )                        + 
              TYPE(*CHAR     )                        + 
              LEN(3          )                          
   DCL        VAR(&daywrk    )                        + 
              TYPE(*DEC      )                        + 
              LEN(5 0        )                          
   DCL        VAR(&dow       )                        + 
              TYPE(*DEC      )                        + 
              LEN(1 0        )                          
   DCL        VAR(&dpy       )                        + 
              TYPE(*DEC      )                        + 
              LEN(3 0        )                          
   DCL        VAR(&enddate   )                        + 
              TYPE(*CHAR     )                        + 
              LEN(6          )                          
   DCL        VAR(&fday      )                        + 
              TYPE(*CHAR     )                        + 
              LEN(1          )                          
   DCL        VAR(&jdays     )                        + 
              TYPE(*DEC      )                        + 
              LEN(5 0        )                          
   DCL        VAR(&jdaysc    )                        + 
              TYPE(*CHAR     )                        + 
              LEN(3          )                          
   DCL        VAR(&jul       )                        + 
              TYPE(*CHAR     )                        + 
              LEN(5          )                          
   DCL        VAR(&jyer      )                        + 
              TYPE(*DEC      )                        + 
              LEN(3 0        )                          
   DCL        VAR(&jyerc     )                        +
              TYPE(*CHAR     )                        +
              LEN(3          )                         
   DCL        VAR(&ldiv      )                        +
              TYPE(*DEC      )                        +
              LEN(3 0        )                         
   DCL        VAR(&rundate   )                        +
              TYPE(*CHAR     )                        +
              LEN(8          )                         
   DCL        VAR(&today     )                        + 
              TYPE(*CHAR     )                        + 
              LEN(9          )                          
   DCL        VAR(&work      )                        +
              TYPE(*DEC      )                        +
              LEN(6 0        )                         
   DCL        VAR(&work2     )                        +
              TYPE(*DEC      )                        +
              LEN(6 0        )                         
   DCL        VAR(&work3     )                        +
              TYPE(*DEC      )                        +
              LEN(9 3        )                         
   DCL        VAR(&year      )                        + 
              TYPE(*CHAR     )                        + 
              LEN(2          )                          
   DCL        VAR(&yr        )                        + 
              TYPE(*DEC      )                        + 
              LEN(3 0        )                          



   CHGVAR     VAR(&daywrk    )                        + 
              VALUE(&days    )                          
                                                         
   CVTDAT     DATE(&begdate  )                        + 
              TOVAR(&jul     )                        + 
              FROMFMT(*MDY   )                        + 
              TOFMT(*JUL     )                        + 
              TOSEP(*NONE    )                          
                                                        
   CHGVAR     VAR(&jyer      )                        +
              VALUE(%sst(&jul 1 2))                    
   CHGVAR     VAR(&jdays     )                        +
              VALUE(%sst(&jul 3 3))                    
                                                        
   IF         COND(&jyer *eq 0)                       + 
              THEN(CHGVAR                             + 
              VAR(&jyer      )                        + 
              VALUE(&jyer + 100))                       
                                                       
leapchk:                                               
                                                       
   CHGVAR     VAR(&ldiv      )                        +
              VALUE(&jyer / 4)                         
   CHGVAR     VAR(&dpy       )                        +
              VALUE(      365)                         
                                                       
   IF         COND((&ldiv * 4) *eq &jyer)             +
              THEN(CHGVAR                             +
              VAR(&dpy       )                        +
              VALUE(     366))                         
                                                       
   IF         COND(&daywrk *gt &dpy)                  +
              THEN(DO        )                         
                                                       
      CHGVAR     VAR(&daywrk    )                     +
                 VALUE(&daywrk - &dpy)                  
      CHGVAR     VAR(&jyer      )                     + 
                 VALUE(&jyer + 1)                       
      GOTO       CMDLBL(leapchk )                       
                                                        
   ENDDO                                                
                                                        
   CHGVAR     VAR(&jdays     )                        + 
              VALUE(&jdays + &daywrk)                   
                                                        
daycalc:                                                
                                                        
   IF         COND(&jdays *gt &dpy)                   + 
              THEN(DO        )                          
                                                        
      CHGVAR     VAR(&jdays     )                     + 
                 VALUE(&jdays - &dpy)                   
      CHGVAR     VAR(&jyer      )                     + 
                 VALUE(&jyer + 1)                       
      CHGVAR     VAR(&ldiv      )                     + 
                 VALUE(&jyer / 4)                       
      CHGVAR     VAR(&dpy       )                     + 
                 VALUE(365      )                       
      IF         COND((&ldiv * 4) *eq &jyer)          + 
                 THEN(CHGVAR                          + 
                 VAR(&dpy       )                     + 
                 VALUE(366     ))                       
      GOTO       CMDLBL(daycalc )                       
                                                        
   ENDDO                                                
                                                        
daycaln:                                                

   IF         COND(&jdays *le  0)                     + 
              THEN(DO        )                          
                                                        
      CHGVAR     VAR(&jyer      )                     + 
                 VALUE(&jyer - 1)                       
      CHGVAR     VAR(&ldiv      )                     + 
                 VALUE(&jyer / 4)                       
      CHGVAR     VAR(&dpy       )                     + 
                 VALUE(365      )                       
                                                        
      IF         COND((&ldiv * 4) *eq &jyer)          + 
                 THEN(CHGVAR                          + 
                 VAR(&dpy       )                     + 
                 VALUE(366     ))                       
                                                        
      CHGVAR     VAR(&jdays     )                     + 
                 VALUE(&jdays + &dpy)                   
                                                        
      GOTO       CMDLBL(daycaln )                       
                                                        
   ENDDO                                                
                                                        
   IF         COND(&jyer *ge 100)                     + 
              THEN(CHGVAR                             + 
              VAR(&jyer      )                        + 
              VALUE(&jyer - 100))                       
                                                       
   CHGVAR     VAR(&jyerc     )                        +
              VALUE(&jyer    )                         
   CHGVAR     VAR(&jdaysc    )                        +
              VALUE(&jdays   )                         
   CHGVAR     VAR(&jul       )                        +
              VALUE(%sst(&jyerc 2 2) *cat &jdaysc)     
                                                       
   CVTDAT     DATE(&jul      )                        +
              TOVAR(&enddate )                        + 
              FROMFMT(*JUL   )                        + 
              TOFMT(*MDY     )                        + 
              TOSEP(*NONE    )                          
                                                        
ENDPGM


Hope this helps.


Todd Kidwell (Netstar)
AS/400 System Administrator

>>> <rbrightman@amclog.com> 01/07/00 10:15AM >>>


Is there a simpler way of adding a certain number of days to a date  to get a
new date (in CL only)? I know I can call a home made RPG progam, But can it be
done in CL only?

Rick


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






Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot 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 here. If you have questions about this, please contact