So what format is this?
11121211
YYYYMMDD or MMDDYYYY
That being said, review this:
D ds
D testSet 90 inz('2008-01-31123108 11/23/08
+
D 01/14/200802222007 013208
+
D 1234 11121211 010101
')
D TestArray 10 overlay(testSet) dim(9)
D ds
D testdate10 10a
D testdate8 8a overlay(testdate10)
D testdate6 6a overlay(testdate10)
D x s 5i 0
D length s 5i 0
D dspmsg s 25a
D
/free
*inlr=*on;
for x=1 to %elem(TestArray);
testdate10=%trim(TestArray(x));
length=%len(%trim(TestArray(x)));
if length=10;
test(de) *iso testdate10;
if not %error;
dspmsg=testdate10+' *iso';
dsply dspmsg;
iter;
ENDIF;
test(de) *usa testdate10;
if not %error;
dspmsg=testdate10+' *usa';
dsply dspmsg;
iter;
ENDIF;
dspmsg=testdate10+' bad10';
dsply dspmsg;
iter;
endif; // length=10
if length=8;
test(de) *iso0 testdate8;
if not %error;
dspmsg=testdate8+' *iso0';
dsply dspmsg;
iter;
ENDIF;
test(de) *usa0 testdate8;
if not %error;
dspmsg=testdate8+' *usa0';
dsply dspmsg;
iter;
ENDIF;
test(de) *mdy testdate8;
if not %error;
dspmsg=testdate8+' *mdy';
dsply dspmsg;
iter;
ENDIF;
test(de) *ymd testdate8;
if not %error;
dspmsg=testdate8+' *ymd';
dsply dspmsg;
iter;
ENDIF;
dspmsg=testdate8+' bad8';
dsply dspmsg;
iter;
endif; // length=8
if length=6;
test(de) *mdy0 testdate6;
if not %error;
dspmsg=testdate6+' *mdy0';
dsply dspmsg;
iter;
ENDIF;
test(de) *ymd0 testdate6;
if not %error;
dspmsg=testdate6+' *ymd0';
dsply dspmsg;
iter;
ENDIF;
dspmsg=testdate6+' bad6';
dsply dspmsg;
iter;
endif; // length=6
dspmsg=testdate10+' pucked';
dsply dspmsg;
iter;
ENDFOR;
/end-free
call rob/testdate
DSPLY 2008-01-31 *iso
DSPLY 123108 *mdy0
DSPLY 11/23/08 *mdy
DSPLY 01/14/2008 *usa
DSPLY 02222007 *usa0
DSPLY 013208 bad6
DSPLY 1234 pucked
DSPLY 11121211 *iso0
DSPLY 010101 *mdy0
dspjoblog
Rob Berendt
As an Amazon Associate we earn from qualifying purchases.