Date Formatting in RPG

100 pts.
Tags:
RPG
RPG IV
RPGLE Program
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?

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following