Hi Joel,

I just got the digest from the mailing list. I use the date functions all
the time--they are definitely not full of bugs. We've found a couple of
oddities, but IBM quickly provided fixes for these.

Let me see if I understand correctly. Do I understand that what you want
is to translate from a field containing (for example), "20121128" and end
up with the format "2012-11-18"?

You can use EXTRACT-DATE-TIME, but I generally use CONVERT-DATE-TIME. The
EXTRACT function is intended to extract a portion of the date-time
field--e.g., the month or the year. If you simply are converting from one
format to another, ILE COBOL handles all the work for you. If you're
confident that ws-date always contains a date, try the following:

move ws-date to A0468X-DUE-DATE of AFTR

This is using the following working-storage assumptions:

01 ws-date format date '@Y%m@d'.

01 AFTR.
05 A0468X-DUE-DATE format date '@Y-%m-%d'.

If ws-date is not defined in working-storage as a FORMAT DATE field, then
you'll want to use the following:

move function CONVERT-DATE-TIME (ws-date DATE '@Y%m%d') to A0468X-DUE-DATE
of AFTR.

This example uses the following working-storage assumptions:

01 ws-date pic 9(8).

01 AFTR.
05 A0468X-DUE-DATE format date '@Y-%m-%d'.

If this isn't what you have in mind, post another message with the formats
of WS-DATE and A0468X-DUE-DATE. I'm convinced there's nothing with dates
that ILE COBOL can't handle.

Michael Quigley
Computer Services
The Way International
419 753-1222

cobol400-l-bounces@xxxxxxxxxxxx wrote on 11/28/2012 04:53:57 PM:
----- Message from "Stone, Joel" <Joel.Stone@xxxxxxxxxx> on Wed, 28
Nov 2012 19:57:32 +0000 -----


"'COBOL Programming on the iSeries/AS400'" <cobol400-l@xxxxxxxxxxxx>


Re: [COBOL400-L] how to extract the most common date format - YYYYMMDD

Thanks but here is IBM doc example from "Websphere Development
Studio ILE COBOL reference" v5 SC09-2539-02:

MOVE FUNCTION EXTRACT-DATE-TIME (date-2 '%m/%d') to alphanum-1.

It's a stinker - I guess I will have to format as 2012/11/28 and
then SUBSTRING out the slashes.

It seems that once the slashes or spaces are gone from the edit
string, the compiler chokes because it thinks it is numeric.

Is it possible that it is impossible to pull the most common date
format? Does no one else use the cobol compiler with dates?

So here is the ugly code that I created:

move function EXTRACT-DATE-TIME (ws-date '@Y/%m/%d')
to ws-date-yyyy-mm-dd
string ws-date-yyyy-mm-dd (1:4)
ws-date-yyyy-mm-dd (6:2)
ws-date-yyyy-mm-dd (9:2)
delimited by size into A0468X-DUE-DATE of AFTR

Does anyone else use DATE functions in COBOL/ILE? Maybe the are
full of bugs??

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2021 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.