ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

I need help Calculating Dates in CL

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

  • I need help Calculating Dates in CL

    Hello,

    I need some help to calculate a week ago in cl.

    I want to use variables in cl and take todays date and subtract 7 days from it.

  • #2
    Re: I need help Calculating Dates in CL

    use cvtdat to convert the date to *JUL
    then subtract 7 days and convert back to the format of your choice.
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: I need help Calculating Dates in CL

      I tried to convert to *JUL but when I try a mathmatic operation on that number it fails.

      When I changed my variabl to *DEC len(6) it also fails because it says it is not the right type of value and that I neeed to make it *CHAR minlen of 5.

      does that make sense

      Comment


      • #4
        Re: I need help Calculating Dates in CL

        just remember you must take in account the when the day is like 1 jan 2007 and you subtract the year will be 2006.

        anyway
        PHP Code:
                  PGM                                                        
                  DCL        
        VAR(&DATETYPE(*CHARLEN(6)                   
                  
        DCL        VAR(&OUTDATETYPE(*CHARLEN(6)                
                  
        DCL        VAR(&JULIANTYPE(*CHARLEN(5)                 
                  
        DCL        VAR(&DECJULIANTYPE(*DECLEN(5)               
                                                                             
                  
        RTVSYSVAL  SYSVAL(QDATERTNVAR(&DATE)                     
                  
        CVTDAT     DATE(&DATETOVAR(&JULIANTOFMT(*JUL) +        
                               
        TOSEP(*NONE)                                  
                  
        CHGVAR &DECJULIAN &JULIAN                                  
                  CHGVAR     
        VAR(&DECJULIANVALUE(&DECJULIAN 1)           
                  
        CHGVAR &JULIAN  &DECJULIAN                                 
                  CVTDAT     DATE
        (&JULIANTOVAR(&OUTDATEFROMFMT(*JUL) +   
                               
        TOFMT(*YMDTOSEP(*NONE)                      
                                                                             
                  
        ENDPGM 
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: I need help Calculating Dates in CL

          Thank you that worked.

          Comment


          • #6
            Re: I need help Calculating Dates in CL

            Ok,

            You stated earlier that if the date was near the beginning of the year the year would change. however when I tested this using a date of 010107 and converted to Julian i came up with 7001 for julian date.

            When I subtracted 7 days i came up with 6994. this obviously is not correct for a Julian date. how can I solve for this case. I need to put this into my job schedule and dont want to have to remember that It wont work for the first week of the year.

            Thank you in advance for all f your help here. This is a great site and has helped me to answer alot of my questions.

            Comment


            • #7
              Re: I need help Calculating Dates in CL

              Well your gonna have to test this but something like this
              RPG is so much better at the date stuff and as anyone can tell you
              I hate CL

              PHP Code:
                           PGM
                           DCL        
              VAR(&DATETYPE(*CHARLEN(6)
                           
              DCL        VAR(&OUTDATETYPE(*CHARLEN(6)
                           
              DCL        VAR(&JULIANTYPE(*CHARLEN(5)
                           
              DCL        VAR(&DECJULIANTYPE(*DECLEN(5)
                           
              DCL        VAR(&YEARTYPE(*CHARLEN(2)
                           
              DCL        VAR(&DECYEARTYPE(*DECLEN(2)
                           
              DCL        VAR(&DAYSTYPE(*CHARLEN(3)
                           
              DCL        VAR(&DAYSTYPE(*CHARLEN(3)
                           
              DCL        VAR(&DECDAYSTYPE(*DECLEN(3)

                           
              RTVSYSVAL  SYSVAL(QDATERTNVAR(&DATE)

                           
              CHGVAR     VAR(&YEARVALUE(%SST(&DATE 1 2))
                           
              CHGVAR     VAR(&DECYEARVALUE(&YEAR)
                           
              CHGVAR     VAR(&DAYSVALUE(%SST(&DATE 3 3))
                           
              CHGVAR     VAR(&DECDAYSVALUE(&DAYS)

                           IF         
              COND(&DECDAYS <= 7THEN(DO)
                           
              CHGVAR     VAR(&DECYEARVALUE(&DECYEAR 1)
                           
              CHGVAR     VAR(&DECDAYSVALUE(365 - (- &DECDAYS))
                           
              ENDDO
                           
              ELSE  CMD(DO)

                           
              CVTDAT     DATE(&DATETOVAR(&JULIANTOFMT(*JUL) +
                                        
              TOSEP(*NONE)
                           
              CHGVAR &DECJULIAN &JULIAN
                           CHGVAR     
              VAR(&DECJULIANVALUE(&DECJULIAN 1)
                           
              CHGVAR &JULIAN  &DECJULIAN
                           CVTDAT     DATE
              (&JULIANTOVAR(&OUTDATEFROMFMT(*JUL) +
                                        
              TOFMT(*YMDTOSEP(*NONE)
                           
              ENDDO

                           ENDPGM

              All my answers were extracted from the "Big Dummy's Guide to the As400"
              and I take no responsibility for any of them.

              www.code400.com

              Comment


              • #8
                Re: I need help Calculating Dates in CL

                I believe Julian is 5 digits (YYDDD) not 4.

                Comment


                • #9
                  Re: I need help Calculating Dates in CL

                  It is 5 Im not paying attention
                  plus I forgot to turn back to a "real date"

                  PHP Code:
                                PGM
                               DCL        
                  VAR(&DATETYPE(*CHARLEN(6VALUE('010107')
                               
                  DCL        VAR(&OUTDATETYPE(*CHARLEN(6)
                               
                  DCL        VAR(&JULIANTYPE(*CHARLEN(5)
                               
                  DCL        VAR(&DECJULIANTYPE(*DECLEN(5)
                               
                  DCL        VAR(&YEARTYPE(*CHARLEN(2)
                               
                  DCL        VAR(&DECYEARTYPE(*DECLEN(2)
                               
                  DCL        VAR(&DAYSTYPE(*CHARLEN(3)
                               
                  DCL        VAR(&DAYSTYPE(*CHARLEN(3)
                               
                  DCL        VAR(&DECDAYSTYPE(*DECLEN(3)

                         
                  /*    RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&DATE) */
                               
                  CVTDAT     DATE(&DATETOVAR(&JULIANFROMFMT(*MDY) +
                                            
                  TOFMT(*JULTOSEP(*NONE)

                               
                  CHGVAR     VAR(&YEARVALUE(%SST(&JULIAN 1 2))
                               
                  CHGVAR     VAR(&DECYEARVALUE(&YEAR)
                               
                  CHGVAR     VAR(&DAYSVALUE(%SST(&JULIAN 3 3))
                               
                  CHGVAR     VAR(&DECDAYSVALUE(&DAYS)

                               IF         
                  COND(&DECDAYS <= 7THEN(DO)
                               
                  CHGVAR     VAR(&DECYEARVALUE(&DECYEAR 1)
                               
                  CHGVAR     VAR(&DECDAYSVALUE(365 - (- &DECDAYS))
                               
                  chgvar &YEAR &DECYEAR
                               chgvar 
                  &DAYS &DECDAYS
                               CHGVAR     
                  VAR(&JULIANVALUE(&YEAR || &DAYS)
                               
                  CVTDAT     DATE(&JULIANTOVAR(&OUTDATEFROMFMT(*JUL) +
                                            
                  TOFMT(*YMDTOSEP(*NONE)
                               
                  ENDDO
                               
                  ELSE  CMD(DO)
                               
                  CHGVAR &DECJULIAN &JULIAN
                               CHGVAR     
                  VAR(&DECJULIANVALUE(&DECJULIAN 1)
                               
                  CHGVAR &JULIAN  &DECJULIAN
                               CVTDAT     DATE
                  (&JULIANTOVAR(&OUTDATEFROMFMT(*JUL) +
                                            
                  TOFMT(*YMDTOSEP(*NONE)
                               
                  ENDDO

                               ENDPGM
                  

                  All my answers were extracted from the "Big Dummy's Guide to the As400"
                  and I take no responsibility for any of them.

                  www.code400.com

                  Comment


                  • #10
                    Re: I need help Calculating Dates in CL

                    relax...go back to wake boarding!

                    you pointed the person in the correct direction.

                    Comment


                    • #11
                      Re: I need help Calculating Dates in CL

                      Your right........... went to a lake yesterday with a 225 horsepower boat..
                      we spent as much time in the air as we did in the water....summer ROCKs!
                      All my answers were extracted from the "Big Dummy's Guide to the As400"
                      and I take no responsibility for any of them.

                      www.code400.com

                      Comment


                      • #12
                        Re: I need help Calculating Dates in CL

                        Thanks again that worked wonderfully. I wish I were an RPG programmer and could work it this way. However I work mostly with CL and feel more comfortable with creating my utlities in this manner.

                        RPG would take ME 8 times as long to figure out.

                        Thanks again you are great!!

                        Comment


                        • #13
                          Re: I need help Calculating Dates in CL

                          *tsk* *tsk* *tsk*...

                          There goes his ego again!!

                          Comment

                          Working...
                          X