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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating a Date using IsDate doesn't seem to do the trick... 1

Status
Not open for further replies.

KingRichard3

Programmer
Feb 9, 2005
58
US
The following evaluates as TRUE:
Code:
Isdate("1/1/'04") and Isdate("1/1/.04") and Isdate("1/1/04*")
Is it possible to use the IsDate() function to validate a date before sending it to a database? It seems to screen out all other bad input, but if the user inputs one of the above examples, the database is most unhappy...

Thanks,
Rick
 
The problem is that it sees it as a valid date. I would suggest writing it to a date variable first and then formatting it once it is in that variable (you can trap errors when assigning it to the date variable to account for any invalid dates). e.g.
Code:
        Try
            Dim MyDate As Date
            MyDate = "1/1/.04"
            ' Now apply the necessary formatting
        Catch ex As Exception
            ' Invalid Date
        End Try

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Great idea! It worked! (Until I input 3/305 - .NET's Date decided it was = 3/0305 and SQL Server decided to blow up when it saw that date...)

:)
Rick
 
Yeah you may also have to implement additional checks such as a date range to make sure the year is between what you define as a valid range.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top