Date Formatting in RPG
70 pts.
0
Q:
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?
ASKED: Aug 11 2009  10:22 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
2005 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
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 Answered: Aug 13 2009  2:05 PM GMT by WilsonAlano   2005 pts.
Latest Contributors: Cwc   3860 pts., Nitzinger   180 pts., Satsho   1235 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



0