I would check in COBOL the formal validity of a date. The LE CEESECS function seems to be suitable for this task. I tried to use it but doesn't seem to regard the date separator (if it is wrong o right) . Look at this. If you specify the date format
11/11/2010 22:11:59.900 with pic-string YYYY-MM-DD HH: MI: SS.999 everything is ok, the return value is (.13508892719900000 E 11) . But even if you use this wrong date format
2010-11*11 22:11:59.900 with pic-string YYYY-MM-DD HH: MI: SS.999 ("*" to separate month / day) also works correctly, CEESECS then converts into seconds (.13508892719900000 E 11). In this latter case CEESECS should return error 2525 (CEESECS detected non-numeric data in a numeric field, or the timestamp string did not match the picture string. )
Is there a mistake?
I suspect that the * is considered a valid delimiter, hence there's no error.
Any symbol is accepted! Not only 'star' "*"!
2010é11é11 22:11:59.900 with a pic-string "YYYY-MM-DD HH: MI: SS.999" CEESEECS gives correctly .13508892719900000 E 11 seconds !
"è" should not be a valid separator , I hope !
Review CEELOCT, which returns the current date/time as a format of CCYYMMDDHHMMSS999, along with a variety of picture clauses.
If you also need the GMT Offset-to-Local as a signed HHMM, review CEEGMTO.
However, COBOL FUNCTION CURRENT-DATE (introduced with COBOL/370) returns a value of CCYYMMDDHHMMSSTH+/-HHMM, combining both above values, except milliseconds in the time.
If you only need to check the validity of an existing date, review CEEDAYS.
CEEDAYS suffers the same problem of CEESECS,
Any character is accepted as a date separator, but that is expected , see the LE Programming Reference ("Whenever characters such as colons or slashes are included in the picture_string (such as HH:MI:SS YY/MM/DD), they count as placeholders but are otherwise ignored. " )
For CEESECS is different, as stated in LE Programming Reference, " A length-prefixed character string representing a date or timestamp in a format matching that specified by picture_string..... After a valid date is parsed, as determined by the format of the date you specify in picture_string, ....".
Pic-string seems to be ( or must be ) a model for date ! If date doesn't respect <pic-string> format, CEESECS should return a error. Any idea about ?
Joined: 14 Jan 2008 Posts: 2504 Location: Atlanta, Georgia, USA
When I've used CEEDAYS, the picture clause never includes any edit characters, it's just YYYYMMDD or YYYYDDD or a variety of other formats without edit characters. Keep in mind that the picture clause length is 1-Byte Binary/Hex. (See correction below)
If all you're doing is validating the date via CEEDAYS and the date is correct, then the first 2-Bytes of the feedback-area (4th-parm) will equal X'00's, upon return.
Validating the time is easy enough to do programmatically and I won't get into that.
In fact, you should only call CEEDAYS after performing your own programmatic tests, which are also easy enough to do.