Date in COBOL/400

295 pts.
Tags:
AS/400
COBOL
I have a character field having length 10 charsm say DATE1 PIC X(10). Now I want to check if the date in this field is in format MM/DD/YYY then how can I check it? and if I want to add 60 days to this date then how to do it in CBL program?

Answer Wiki

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

To answer your first question — there isn’t any “good” way. The problem has to do with months and days. Is 03/04/2008 March 4 2008 (mm/dd/yy) or is it April 3 2008 (dd/mm/yy)? Both usage styles are quite valid and represent the preferred format for a date in various cultures. So a significant portion of each month (the first 12 days if you will of every month) cannot be tested with certainty.

As to adding 60 days to a date, the below should do the trick:

DATA DIVISION.
WORKING-STORAGE SECTION.
01 Some-Date PIC X(10) VALUE "03/04/2008".
01 A-Date-Field FORMAT DATE "%m/%d/@Y".

PROCEDURE DIVISION.
MAIN-LINE.
MOVE FUNCTION CONVERT-DATE-TIME(Some-Date DATE "%m/%d/@Y")
TO A-Date-Field.
DISPLAY A-Date-Field.
MOVE FUNCTION ADD-DURATION(A-Date-Field DAYS 60)
TO A-Date-Field.
DISPLAY A-Date-Field.
STOP RUN.

There are also other intrinsic functions, such as TEST-DATE-TIME but, as mentioned above, they are more oriented to testing the values given a format — and you don’t have a good reliable way of testing the format when month and day values overlap. These functions can be found in the ILE COBOL Reference.

Bruce Vining

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