IBMi (AS400) fans only - Reverse date 6 0 in one instruction


#IBMiSample


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


It should contain a number rapresenting a DATE in yymmdd (i.e 210208 - February 8, 2021) or ddmmyy format  (i.e 080221 - February 8, 2021).

The following instructions turns yymmdd to ddmmyy or viceversa (the other way around).


OTDTP0 zoned(6);

OTDTP0 = %dec(%char(%date(OTDTP0:*ymd):*dmy0):6:0); // yymmdd to ddmmyy

OTDTP0 = %dec(%date(OTDTP0:*ymd):*dmy); // yymmdd to ddmmyy


I appreciate all the comments made on this blog.

Comments

  1. //-- %char is not necesssary, mmddyy to yymmdd:

    YYMMDD = %Dec(%date(MMDDYY:*mdy):*ymd);

    ReplyDelete
    Replies
    1. Thanks for your help. I updated the post according to your suggestion

      Delete
  2. I find using a monitor/on-error on the conversion line catches invalid dates better than checking for not zero.

    ReplyDelete
  3. Instead of qualifying that your decimal field <> *zeros, if you monitor on the conversion, you can set the value to zero, or a date you can identify as a problem without the program bombing. (Monitor/conversion/on-error/eval to zero/endmon)

    ReplyDelete

Post a Comment

Popular posts from this blog

IBMi (AS400) fans only ‘ Memories (IBM Coding Forms)

IBM i (AS400) fans only ' How to read a TXT file in the IFS with SQL