Validation of a date in Rexx
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> TSO and ISPF

#1: Validation of a date in Rexx Author: vikramdr PostPosted: Sat Feb 15, 2003 6:43 am
    —
Hi,

I am learning rexx. I would like to know can v validate a string for proper date. I know date() will give the system date.

Ex: chk4date = 20020012 /*yyyymmdd*/
Since mm is 00, its not a valid date....

Is there any way to validate that ?

Thanks.

#2:  Author: semigeezerLocation: Atlantis PostPosted: Sat Feb 15, 2003 12:41 pm
    —
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 */

#3:  Author: warp5Location: Germany PostPosted: Tue Feb 18, 2003 2:17 am
    —
You could test it like this:

/* REXX */
trace r
signal on syntax name date_wrong
x = date('E','20020012','S')
say 'Date format is correct'
exit

date_wrong:
say 'Date format is incorrect'
exit



MVSFORUMS.com -> TSO and ISPF


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group