|
Here's a simpler method for ILE COBOL (source type CBLLE):
Working-storage section.
01 Work-date pic 9(6).
01 Display-date pic 9(8).
01 Validate-date-time pic 1.
88 Valid-date-time value b'1'.
88 Invalid-date-time value b'0'.
01 Date-format pic 1.
88 2-digit-year value b'0'.
88 4-digit-year value b'1'.
Procedure Division.
evaluate true
when Display-date > 1000000
move function
test-date-time (Display-date date '@Y%m%d')
to Validate-date-time
set 4-digit-year to true
when other
move Display-date to Work-date
move function test-date-time (Work-date date '%y%m%d')
to Validate-date-time
set 2-digit-year to true
end-evaluate
The above logic should work for dates in the format yyyymmdd or yymmdd. If
the date is valid then the condition 'Valid-date-time' is true. If the
date is not valid then the condition 'Invalid-date-time' is true. If you
have a 6 digit date, the condition '2-digit-year' is set to true. If an 8
digit date, then the condition '4-digit-year' is set to true.
We use the above logic (albeit modified to handle date in USA format) in a
service program so we can call it anywhere we need to validate a date.
Michael Quigley
AS/400 Programming Coordinator
The Way International
www.TheWay.org
Original message:
------------------------------
Sent: Friday, April 08, 2005 4:37 PM
To: Cobol400-L@Midrange. Com (E-mail)
Subject: [COBOL400-L] how to validate date in cobol400
hi all!!
how do we validate differents formats of dates, especially iso
format(yyyy/mm/dd).
TIA!!!
GODBLESS!!!
Wilson
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.