Code: |
/* Rexx - Date validation subroutine and driver */
val='20020231' Say validDate(val) Return validDate: Procedure /* Return 1 for valid yyyymmdd, or 0 */ indate=Arg(1) /* All numeric and correct length ? */ If translate(indate,'0000000000','0123456789') \= '00000000' Then Return 0 /* Is month valid ? */ Parse Var indate yyyy 5 mm 7 dd Say yyyy mm dd If mm <1 | mm > 12 Then Return 0 /* Now turn date into number of days, and back, then compare. */ /* This is done this way to let rexx worry about leap years */ /* and the number of days in each month */ base=date('B',yyyy||mm||'01','S')-1 /* Get date for 1st of month -1 */ newdate=date('S',base+dd,'B') /* Add day of month, convert back to YYYYMMDD */ If newdate \= indate Then /* If new yyyymmdd doesn't match original */ Return 0 /* Bad date - Day of month invalid for this month */ Return 1 /* If we got here, it is valid */ |
output generated using printer-friendly topic mod. All times are GMT - 5 Hours