MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Validation of a date in Rexx

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF
View previous topic :: View next topic  
Author Message
vikramdr
Beginner


Joined: 15 Feb 2003
Posts: 15
Topics: 11

PostPosted: Sat Feb 15, 2003 6:43 am    Post subject: Validation of a date in Rexx Reply with quote

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.
_________________
Vikram
Back to top
View user's profile Send private message
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Sat Feb 15, 2003 12:41 pm    Post subject: Reply with quote

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 */
Back to top
View user's profile Send private message Visit poster's website
warp5
Intermediate


Joined: 02 Dec 2002
Posts: 429
Topics: 18
Location: Germany

PostPosted: Tue Feb 18, 2003 2:17 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group