× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



We get a lot of data coming in with dates in all kinds of formats. There
had been earlier discussions on the forum about parsing dates with
separators by %Date and I wanted something definitive on what worked or
did not work and whether it was a bug.

I wrote the code below to test %Date with character dates and formatting
characters and submitted the results to IBM support. The full code is
below.

Result = CheckAlpha('1070714':'*CYMD0'); // Works
Result = CheckAlpha('07/14/07':'*MDY/'); // Works
Result = CheckAlpha('7/14/07':'*MDY/'); // Fails
Result = CheckAlpha('7/7/07':'*MDY/'); // Fails
Result = CheckAlpha('07/7/07':'*MDY/'); // Fails
Result = CheckAlpha('7/14/2007':'*USA/'); // Works
Result = CheckAlpha('7/7/2007':'*USA/'); // Works
Result = CheckAlpha('07/7/2007':'*USA/'); // Works
Result = CheckAlpha('7/07/2007':'*USA/'); // Works
Result = CheckAlpha('07/07/2007':'*USA/'); // Works
Result = CheckAlpha('2007-7-7':'*ISO-'); // Works
Result = CheckAlpha('2007-7-07':'*ISO-'); // Works
Result = CheckAlpha('2007-07-7':'*ISO-'); // Works

Why would *USA and *ISO dates with values like '7/7/2007 or '2007-7-7'
work but not a *MDY of '7/7/07'?

It would seem to me that if the *USA and *ISO work that the *MDY should
work also.

I received the following back.

Quote:

Here is the final word on this issue with the dates:

The RPG documentation says that a valid *USA date is in the form
'MM/DD/YYYY', and that a valid *MDY date is in the form 'MM/DD/YY'.
There is no documented RPG support for dates that have variations such
as 'MM/D/YYYY' for *USA or 'M/D/YY' for *MDY."

Although some dates not in the correct format will be parsed without
error this is not guaranteed by the RPG language. All input dates
should be in the format specified by the RPG language.

End Quote:

They indicated that underneath the RPG compiler is calling MI function
_CVTD to convert the dates. I looked at some documentation on this. Boy,
talk about a dozy. If you are interested, look for _CVTD on the web.

Bottom line is if you are using the %Date function to parse character
dates with separators, you are going to need to normalize the dates
before you pass them to %Date.

I am going to add a function to my common string functions service
program to do this and return a properly formatted date that %Date is
guaranteed to digest.

Seems a shame that the dates are not handled correctly but oh well.

Now I know for sure that it is a feature and not a bug and that it does
not work.

d CheckAlpha...
d pr d
d PR_InAlphaDate...
d 10a Value
d PR_InFormat...
d 6a Value

d Result...
d s d
/Free

Result = CheckAlpha('1070714':'*CYMD0');
Result = CheckAlpha('07/14/07':'*MDY/');
Result = CheckAlpha('7/14/07':'*MDY/');
Result = CheckAlpha('7/7/07':'*MDY/');
Result = CheckAlpha('07/7/07':'*MDY/');
Result = CheckAlpha('7/14/2007':'*USA/');
Result = CheckAlpha('7/7/2007':'*USA/');
Result = CheckAlpha('07/7/2007':'*USA/');
Result = CheckAlpha('7/07/2007':'*USA/');
Result = CheckAlpha('07/07/2007':'*USA/');
Result = CheckAlpha('2007-7-7':'*ISO-');
Result = CheckAlpha('2007-7-07':'*ISO-');
Result = CheckAlpha('2007-07-7':'*ISO-');

*InLR = *On;
Return;

/End-Free
p CheckAlpha...
p b
d pi d
d InAlphaDate...
d 10a Value
d InFormat...
d 6a Value

d WorkDate...
d s d
d ErrorMessage...
d s 52a
/Free

Monitor;
Select;
When InFormat = '*CYMD0';
WorkDate = %Date(InAlphaDate:*CYMD0);
When InFormat = '*MDY/';
WorkDate = %Date(InAlphaDate:*MDY/);
When InFormat = '*USA/';
WorkDate = %Date(InAlphaDate:*USA/);
When InFormat = '*ISO-';
WorkDate =%Date(InAlphaDate:*ISO-);
EndSl;
On-Error;
ErrorMessage = 'Date ' + %Trim(InAlphaDate) +
' , Format ' + %Trim(InFormat) + ' failed.';
Dsply ErrorMessage;
WorkDate = %Date('01/01/0001':*USA/);
EndMon;

Return WorkDate;

/End-Free
p e


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-2024 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.