IBMi (AS400) fans only : How to get today's date from CL (Control Language)







 
#IBMiSample

This example gets todays date in format YYMMDD without separators.

With simple changes you get other formats.

             PGM                                              
             DCL        VAR(&DATE) TYPE(*CHAR) LEN(6)         
             RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&DATE)           
             CVTDAT     DATE(&DATE) TOVAR(&DATE) FROMFMT(*MDY)
                          TOFMT(*YMD) TOSEP(*NONE)            
             SNDPGMMSG MSG(&DATE)                             
             ENDPGM                                           

Comments

  1. If you want the power of db2 date format or calculations you can write a view with the necessary fields and retrieve this in clle. https://github.com/prsbrc/Miscellaneous/tree/master/Receive%20view%20in%20cl%20example

    ReplyDelete
  2. It strikes me as funny that QDATE is stored as MDY - am I correct in thinking that the USA is the only country in the world that uses this format?

    ReplyDelete

Post a Comment

Popular posts from this blog

(IBM i fans only) Efficient WRKSPLF with WSF - How to Search string into spooled files, Sort, and Generate PDFs on IBMi

(IBM i fans only) Detecting and Handling Non-Printable Characters in DB2 SQL Using LOCATE() and REPLACE() Functions

(IBM i fans only) How to Sniff User Access