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



On 2012/3/23 11:28 AM, John Yeung wrote:
For the *USA format, %DATE handles single digits for both month and
day.


That's not a documented feature. RPG officially requires that the month and day each have two digits, with leading zeros if necessary.

I'd assume it wasn't supported, and massage the character value so that it was in mm/dd/yyyy form, and then use %DATE.

The work to massage the value into a correct form for %DATE could actually do the full conversion, but I'd still use %DATE to get the validation.

Untested:

D iso ds
D yyyy 4s 0
D mm 2s 0
D dd 2s 0
D start s 10i 0 inz(1)
/free
mm = getDatePart(string : start : '/');
dd = getDatePart(string : start : '/');
yyyy = getDatePart(string : start : '/');
isoDate = %date(iso : *iso0);

P getDatePart b
D getDatePart pi 10i 0
D string 10a varying const
D start 10i 0
D sep 1a const
D pos s 10i 0
D len s 10i 0
D val s 10a varying
/free
if start > %len(string);
return 0;
endif;

pos = %scan(sep : string : start);
if pos = 0;
val = %subst(string : start);
start = %len(string) + 1;
else;
len = pos - start;
val = %subst(string : start : len);
start = pos + 1;
endif;
return %int(val);
/end-free
P getDatePart e

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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.