Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
Posted: Sat Feb 15, 2003 12:41 pm Post subject:
Here is my stab at it. After some very basic tests of the format, I do one more comparison after converting the date in such a way that rexx handles the problem of Februrary in leap years.
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 */
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum