Hi all,
I would like to know if there is a way to convert a date in format DD/MM/YY to YYYYMMDD.
I think it can be done using *DATE or a similar variable, but in this environment I have no help and I really can´t remember how to do it.
Gabriel
Here is a small sample. Testet on Natural 414 under Com-Plete. But should work the same way under Natural 6.11 Unix:
DEFINE DATA LOCAL
1 D1(A8) INIT <‘22/11/05’>
1 D(D)
1 D2(A8)
END-DEFINE
MOVE EDITED D1 TO D(EM=DD/MM/YY)
MOVE EDITED D(EM=YYYYMMDD) TO D2
WRITE D1 / D / D2
END
Hint:
you have to make your natural coding within a code section:
[ code ] … [/ code ] … without blanks before and after ] [
DEFINE DATA LOCAL
1 D1(A8) INIT <'22/11/05'>
1 D(D)
1 D2(A8)
END-DEFINE
MOVE EDITED D1 TO D(EM=DD/MM/YY)
MOVE EDITED D(EM=YYYYMMDD) TO D2
WRITE D1 / D / D2
END
or you write
1 D2 ( A8 )
because 8 ) … without space inbetween … are converted into smilies wearing sunglases 8)
Be careful when converting dates. If your xx/xx/xx is not a valid mm/dd/yy you will get a runtime error. On MVS you can check for a valid date format using
IF #DATE-MDY = MASK (MM/DD/YY)
MOVE EDITED #DATE-MDY (EM=MM/DD/YY) TO #DATE-D
MOVE EDITED #D TO #DATE-CYMD (EM=YYYYMMDD)
ELSE
WRITE #DATE-MDY 'is not valid date in mm/dd/yy format.'
END-IF