IBMi (AS400) fans only : RPG Free Format get Today's date with a single instruction

In this example, the wToday field is numeric 6 with 0 decimal places.


#IBMiSample

It should contain today's date in yymmdd format

       dcl-s WToday zoned(6);

           wToday = %dec(%char(%date():*ymd0):6:0); // today - oggi


I appreciate all the comments made on this blog.

Comments

  1. Hey Aldo , there is a another issue solution provided by DB2 the example includes timezone as well if needed

    values (current_timestamp , (current_timestamp - current time zone) , dec(varchar_format((current_timestamp - current time zone), 'mmddyy'),6))

    Please try that and let me know
    Best
    Diego

    ReplyDelete
    Replies
    1. Hi Diego, this approach is very useful when dealing with timezone-specific data. I'll definitely give it a try and let you know how it works out.

      Also, I apologize for the tremendous delay in getting back to you. I appreciate your patience and understanding.

      Delete
  2. wToday = %dec(%char(%date():*ymd0):6:0); // today - oggi
    You can change %dec for %int as well making it shorter

    wToday = %int(%char(%date():*ymd0)); // today - oggi

    ReplyDelete
    Replies
    1. Yes, it's true. It also works with %int. Thank you my dear reader.

      Delete

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