Using VBScript, how can I determine if a variable is a valid date or not? [Print this FAQ]
Answer:
Use the IsDate function. IsDate accepts a variable as a single parameter and returns a boolean value - True if the variable can successfully be converted to a date and false if it cannot.
Dim dtValidDate, dtNotValid dtValidDate = "08/01/78" dtNotValid = "Scott"
If IsDate(dtValidDate) then Response.Write (dtValidDate & " is valid<BR>") Else Response.Write (dtValidDate & " is NOT valid<BR>") End If
If IsDate(dtNotValid) then Response.Write (dtNotValid & " is valid<BR>") Else Response.Write (dtNotValid & " is NOT valid<BR>") End If
The output of the above script is: 08/01/78 is valid Scott is NOT valid
For more information be sure to read the technical docs.
FAQ posted by Scott Mitchell at
9/24/2000 3:28:28 PM to the
Dates and Times category.
This FAQ has been viewed 53,379 times.
Do you have a FAQ you'd like to suggest?
Suggestions? Comments? If so, send it in!
Also, if you'd like to be a FAQ Admin (creating/editing FAQs),
let me know! If you are looking for other FAQs, be
sure to check out the 4Guys
FAQ and Commonly Asked Messageboard Questions!