Announcement

Collapse
No announcement yet.

Calculate date

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

  • Calculate date

    Hi!

    I want a cl program that returns the date 2021-07-01 if i it run today.

    ISO Date format = Today
    + 2 month
    DAY = 01


    In the long run i would like to have a CL program that can calculate year, month and day if i send in parameters.

    for example:
    CALL CALCDATE PARM Y-5M+5D01
    Year - 5 Month + 5 Day Set to 01

    Im new to CL, but this will return todays date in iso standard 2021-05-20.

    0001.00 PGM PARM(&DATE)
    0002.00 DCL VAR(&DATE) TYPE(*CHAR) LEN(50)
    0003.00 DCL VAR(&DATE2) TYPE(*CHAR) LEN(6)
    0004.00 DCL VAR(&DATE3) TYPE(*CHAR) LEN(50)
    0005.00 DCL VAR(&MONTH) TYPE(*CHAR) LEN(2)
    0006.00 DCL VAR(&DAY) TYPE(*CHAR) LEN(2)
    0007.00 DCL VAR(&YEAR) TYPE(*CHAR) LEN(2)
    0008.00 RTVSYSVAL SYSVAL(QDATE) RTNVAR(&DATE2)
    0009.00 RTVSYSVAL SYSVAL(QDAY) RTNVAR(&DAY)
    0010.00 RTVSYSVAL SYSVAL(QYEAR) RTNVAR(&YEAR)
    0011.00 RTVSYSVAL SYSVAL(QMONTH) RTNVAR(&MONTH)
    0012.00 CHGVAR VAR(&DAY) VALUE(01)
    0013.00 CVTDAT DATE(&DATE2) TOVAR(&DATE3) TOFMT(*ISO) TOSEP(-)
    0014.00 CHGVAR VAR(&DATE) VALUE('(&YEAR)-(&MONTH)-(&DAY)')
    0015.00 ENDPGM



  • #2
    CL is not designed to do something like that. Use a language that recognizes dates and can do date math to do something like this. I am constantly amazed at people trying to force CL to do stuff it isn't designed to do.

    Comment


    • #3
      Originally posted by RIKKRU1111 View Post
      CALL CALCDATE PARM Y-5M+5D01
      Year - 5 Month + 5 Day Set to 01
      Hi there!

      That sounds like a pretty cool utility. How can we help?

      Comment


      • #4
        Hi!

        DAG0000, which language on an as400 would you recommend?

        Scott Klement
        I need a function that i can call together with parameters that calculates and sends back The date in iso-standard with the date calculated the way i want after the parameters i sent in.
        example: 2021-07(+2)-01(01)

        Comment


        • #5
          Originally posted by RIKKRU1111 View Post
          Scott Klement
          I need a function that i can call together with parameters that calculates and sends back The date in iso-standard with the date calculated the way i want after the parameters i sent in.
          example: 2021-07(+2)-01(01)
          Yes, that's what you said in your first message. So how can we help you with this?

          Do you have a question about it that we could help answer?

          Comment


          • #6
            Originally posted by RIKKRU1111 View Post
            Hi!

            I want a cl program that returns the date 2021-07-01 if i it run today.

            ISO Date format = Today
            + 2 month
            DAY = 01
            I've created a command that does what you want.

            This will add two months to today's date:

            Code:
            CHGDTETME DTETME(*CURRENT) DURATION(*ADD '0000-02-00-00.00.00) RTNVAL(&RESULT)
            To use your example, if run right now 2021-05-22-22.00.00, the command returns 2021-07-22-22.00.00.

            The return variable is a *CHAR so it would be simple to change the day to 01 and ignore the time portion.

            Source code is here: https://sourceforge.net/projects/ibm...te-arithmetic/

            Comment


            • #7
              Originally posted by RIKKRU1111 View Post
              Hi!

              I want a cl program that returns the date 2021-07-01 if i it run today.
              Code:
              DCL  &RESULT *CHAR 19
              DCL    &DATE   *CHAR 10   STG(*DEFINED) DEFVAR(&RESULT 1)
              DCL      &YEAR   *CHAR 4  STG(*DEFINED) DEFVAR(&RESULT 1)
              DCL      &MONTH   *CHAR 2 STG(*DEFINED) DEFVAR(&RESULT 6)
              DCL      &DAY     *CHAR 2 STG(*DEFINED) DEFVAR(&RESULT 9)
              DCL    &TIME   *CHAR 8    STG(*DEFINED) DEFVAR(&RESULT 12)
              DCL      &HOUR   *CHAR 2  STG(*DEFINED) DEFVAR(&RESULT 12)
              DCL      &MINUTE *CHAR 2  STG(*DEFINED) DEFVAR(&RESULT 15)
              DCL      &SECOND *CHAR 2  STG(*DEFINED) DEFVAR(&RESULT 18)
              
              
              CHGDTETME DTETME(*CURRENT) DURATION(*ADD '0000-02-00-00.00.00') RTNVAL(&RESULT) /* 2 months from now */
              CHGVAR &DAY VALUE('01')
              
              /* if run on the date of your post, 2021-05-20, then  &DATE is '2021-07-01' */
              DTETME can be any valid timestamp, any DURATION can be added or subtracted so long as the result is between 1/1/0001 and 1/1/10000.

              Comment


              • #8
                Hi!

                Thanks for your answers. As I said im new to this. But its fun and im learning quickly.

                Im not sure if im allowed to bring in outside code to our system.


                I have created a RPGLE program ends with the proper date calculation i want.
                For example "dsply 2021-07-01"

                I need to call the rpg pgm with a CL-pgm and thats no problem.

                But how do i return the dsply-message to a variable in the CL-program?

                CALL MYLIB/RPGTEST
                ??RETURN DSPLY-MESSAGE TO MYVAR HOW??

                Thanks for your help.

                Comment


                • #9
                  Declare a variable to receive the output value, and pass it as a parameter on the call. The RPG program can then update the parameter.

                  CL program:
                  Code:
                  dcl &iso_date type(*char) len(10)
                  
                  call mylib/rpgtest parm(&iso_date)
                  RPG program:
                  Code:
                  dcl-pi *n;             // this is the parameter list
                    iso_date date(*iso); // this is the output date parameter
                  end-pi;
                  
                  iso_date = %date(); // set the parameter to the current date
                  return;
                  Last edited by Barbara Morris; 2 weeks ago. Reason: Edit: fix bad CL syntax

                  Comment

                  Working...
                  X