ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%editc whit %subdt dosen't work

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

  • %editc whit %subdt dosen't work

    I need to extract the day of a timestamp and convert into alfa, i can't use the %char because of zero suppress.

    eval alfa = %editc(%subdt(timestamp:*d):'X' )
    it retuns '00'
    using %char insted of %editc code, retuns ' 5'

    what's wrong?

  • #2
    Hi Thunder,

    You see 00 because the result of %Editc is '0000005', so you see only the first two byte...

    probably there are better solutions, but you can try this:

    Code:
    **free                                                                      
    Dcl-s Day Char(2);                                                          
    
      Evalr Day =  '0' + %Char(%Subdt(%Timestamp() :*D));                      
      Dsply Day;                                                                
      Evalr Day =  '0' + %Char(%Subdt(z'2019-01-31-15.30.10.000000' :*D));      
      Dsply Day;                                                                
      *Inlr = *On;

    Comment


    • #3
      I think this is better
      Eval Day = %subst( %editc (%dec (%time(wzdthr) ) : 'X' ) :5:2)

      At lease it works :P!

      Comment


      • #4
        Or you could go with the original expression, just change the Eval to an EvalR:

        EvalR alfa = %editc(%subdt(timestamp:*d):'X' )

        Comment


        • Thunder
          Thunder commented
          Editing a comment
          That return '00'

        • Brian Rusch
          Brian Rusch commented
          Editing a comment
          I just tested it and it returns '05'. Are you sure you changed the Eval opcode to an EvalR (eval right)?

        • Thunder
          Thunder commented
          Editing a comment
          You right, it works!

      • #5
        EvalR Day2a = %Char(%Date(%Timestamp()):*ISO);

        Ringer

        Comment


        • #6
          To get %SUBDT to only return 2 digits for *D, try adding :2 to %SUBDT:

          Code:
          eval alfa = %editc(%subdt(timestamp : *d [COLOR=#FF0000][B]: 2[/B][/COLOR]) : 'X' )
          The ability to control the length of the %SUBDT result was added in 7.2.
          %SUBDT (Extract a Portion of a Date, Time, or Timestamp), %SUBDT (Subset of Date or Time), built-in functions, date and time, time and date built-in functions, date-time built-in functions


          Also note the fourth parameter for %SUBDT, allowing decimal places for *SECONDS. See the last part of the example.

          Comment


          • #7
            Thanks you all !

            Comment

            Working...
            X