100 pts.
 Date Formatting in RPG
I have a date in a DATE type field in *ISO format (ccyy-mm-dd) However, I want to extract the YY portion. Using %SUBDT(field: *Y) returns CCYY. Is there a nice way of doing this without using a data structure?

Software/Hardware used:
ASKED: August 11, 2009  10:22 AM
UPDATED: August 13, 2009  2:05 PM

Answer Wiki:
Although this isn't quite as clean of a way as I'd like, you could use the character function to convert the date into a character field, from which you could then substring the 3rd & 4th positions of the year, so you could bypass setting up a data structure. Assuming that year is a character field, you could do something like this: Year = %Subst( %Char( SomeDateField: *ISO): 3: 2); CWC /////// Hi, Or you can define a date field with DatFmt(*YMD) to convert original date to this format. Then you can use %Subdt. D DateYMD S D DatFmt(*YMD) (or *DMY) C Eval DateYMD = YourDateISO C Eval YY = %SubDt(DateYMD:*Y) Regards, Wilson Also assuming char field EVAL %SUBST(@temp:3:2) = @YY GL Nitzinger ----------------------- Note that using *Y as the second parameter for the %SubDt BIF will always return a four digit year, even if the date format is *MDY or *YMD, so that is why %SubSt would seem the only sure way of getting a two digit year, at this point. CWC ----------------------- CWC is right! %SubDt will return 4 digits year and as he said %SubSt will be the right way. Wilson
Last Wiki Answer Submitted:  August 13, 2009  2:05 pm  by  Cwc   4,275 pts.
All Answer Wiki Contributors:  Cwc   4,275 pts. , nitzinger   385 pts. , WilsonAlano   2,385 pts. , Satsho   1,245 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _