Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate Time 1

Status
Not open for further replies.
Feb 14, 2000
425
US
Anyone have a slick way to validate Chr String time like
"01:00" as good and "01:61" as not to insure correct user time entry?


Steve Bowman
steve.bowman@ultraex.com

 
Hi
Assuming you follow a 24 hour time format..

myTime = "HH:MM"
lValid = .t.
IF VAL(LEFT(myTime,2)) > 23 OR VAL(LEFT(myTime,2)) < 0
lValid = .f.
ENDIF
IF VAL(RIGHT(myTime,2)) > 59 OR VAL(RIGHT(myTime,2)) < 0
lValid = .f.
ENDIF
IF SUBSTR(myTime,3,1) # &quot;:&quot;
lValid = .f.
ENDIF
RETURN lValid

:)

ramani :)
(Subramanian.G)
 
Here's a simple little routine I wrote. First parameter is the actual time string to check, and the second is either '12' or '24' for which type of time you are checking for:
Code:
*!*****************************************************************************
*!
*!       Function: CHK_TIME
*!
*!*****************************************************************************
FUNCTION chk_time
   PARAMETERS tmptime, whichtime
   
   *... just checks to see if 1-24 and 0 - 59
   
   IF LEN(TRIM(tmptime)) = 0
      RETURN .F.
   ENDIF ( LEN(TRIM(tmptime)) = 0 )
   
   IF whichtime = '12'
      IF !BETWEEN( VAL(LEFT(tmptime, 2)) , 1, 12)
         RETURN .F.
      ENDIF ( !BETWEEN( VAL(LEFT(tmptime, 2)) , 1, 12) )
   ELSE     &&... '24'
      IF !BETWEEN( VAL(LEFT(tmptime, 2)) , 1, 24)
         RETURN .F.
      ENDIF ( !BETWEEN( VAL(LEFT(tmptime, 2)) , 1, 24) )
   ENDIF ( whichtime = '12' )
   
   IF VAL(RIGHT(ALLTRIM(tmptime), 2)) > 59
      RETURN .F.
   ENDIF ( VAL(RIGHT(ALLTRIM(tmptime), 2)) > 59 )
   
   RETURN .T.

-Dave S.-
[cheers]
Even more Fox stuff at:
 
I would not use chr string but would rather use a self correcting value such as time using the date picker. If I really had to I would use something like:

lcTime = IIF(VAL(LEFT(lcTime,2)) > 24, '24'+RIGHT(lcTime,3), lcTime)
lcTime = IIF(VAL(RIGHT(lcTime,2)) > 60, LEFT(lcTime,3)+'60', lcTime)

 
CTOT(&quot;1:61&quot;) will return an empty string so

? empty(ctot(&quot;1:61&quot;)) is true
 
Thank you all for the replies, all very good!

Perryf wins the prize

CTOT(&quot;1:61&quot;) will return an empty string
&quot;it does not need to assume the user will enter &quot;01:61&quot;

Steve Bowman
steve.bowman@ultraex.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top