Problem solve Get help with specific problems with your technologies, process and projects.

How to do date manipulation in a CL

Learn how to retrieving the system date in a CL program and get yesterdays date.

Using the code below you'll be able to do date manipulation in a CL program, and retrieving the system date.

 

DCL        VAR(&SYSDATE) TYPE(*CHAR) LEN(6)

DCL        VAR(&YESTERDAY) TYPE(*DEC) LEN(8 0)
DCL        VAR(&LILIAN) TYPE(*CHAR) LEN(4)
DCL        VAR(&JUNK1) TYPE(*CHAR) LEN(8)
DCL        VAR(&JUNK2) TYPE(*CHAR) LEN(23)
DCL        VAR(&WDATE) TYPE(*CHAR) LEN(8)


RTVSYSVAL  SYSVAL(QDATE) RTNVAL(&SYSDATE)


    /* Get local time from system:   When this call is  +

           complete, &LILIAN will contain the number of +

           days between today and Oct 14, 1582.         */

             CALLPRC    PRC(CEELOCT) PARM(&LILIAN &JUNK1 &JUNK2 *OMIT)

    /*  Subtracting 1 from &LILIAN will produce yesterday's date */

             CHGVAR     VAR(%BIN(&LILIAN)) VALUE(%BIN(&LILIAN) - 1)

    /*  Convert lillian to yyymmdd date  */

             CALLPRC PRC(CEEDATE) PARM(&LILIAN 'YYYYMMDD' &WDATE *OMIT)

             CHGVAR     VAR(&YESTERDAY) VALUE(&WDATE)

Note: CEELOCT and CEEDATE are APIs that exist on the system; you do not need to create them. Click to learn what the CL does.

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.


Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close