Validate date values with IsDate() in Classic ASP

IsDate(expression) tests whether VBScript can interpret a value as a date or time. It is useful when reading uncertain values, but a successful result does not prove that an ambiguous input means the date the user intended.

<%
Dim enteredDate
enteredDate = DateSerial(2007, 2, 28)
Response.Write IsDate(enteredDate)
%>

Output: True. The value is already a valid Date object.

On this page — Show page sectionsHide page sections

Syntax

IsDate(expression)

The function returns the Boolean value True when the expression can be recognized as a date/time and False otherwise. IsDate() uses the current locale when interpreting text.

Original example: invalid date text

<%
Dim my_date
my_date = "February 29, 2007"
Response.Write IsDate(my_date)
%>

Output in an English locale: False; 2007 was not a leap year.

Compare a leap year and non-leap year

<%
Response.Write IsDate(DateSerial(2024, 2, 29)) & "<br>"
Response.Write IsDate("February 29, 2023")
%>

The first result is True. Under an English locale, the second is False. A genuine Date object is more reliable than free-form text.

Locale-sensitive date strings

<%
Dim previousLocale
previousLocale = SetLocale(1033) ' English (United States)
Response.Write IsDate("12/31/2024")
SetLocale previousLocale
%>

Output in a US English locale: True. A string such as 02/03/2026 could be February 3 or March 2 under different regional settings.

Validation rule: If a form asks for year, month and day separately, validate integer ranges, use DateSerial(), and compare the returned Year(), Month() and Day() with the input. IsDate() alone is not enough.

Do not call CDate until a value is checked

<%
Dim valueText, parsedDate
valueText = "December 25, 2026"
If IsDate(valueText) Then
  parsedDate = CDate(valueText)
  Response.Write Year(parsedDate) & "-" & Month(parsedDate) & "-" & Day(parsedDate)
Else
  Response.Write "Please enter a valid date"
End If
%>

The textual month name requires a compatible locale. For stricter validation, prefer an unambiguous numeric input structure.

Numeric form fields versus IsDate

<%
Dim y, m, d, valueDate, validDate
y = 2026: m = 2: d = 31
validDate = False
If y >= 1000 And y <= 9999 And m >= 1 And m <= 12 And d >= 1 And d <= 31 Then
  valueDate = DateSerial(y, m, d)
  validDate = (Year(valueDate) = y And Month(valueDate) = m And Day(valueDate) = d)
End If
Response.Write validDate
%>
False

Safely check a submitted field

<%
Dim rawDate
rawDate = Trim(Request.Form("date_value"))
If Len(rawDate) = 0 Then
  Response.Write "Enter a date"
ElseIf IsDate(rawDate) Then
  Response.Write "Recognized by the current server locale"
Else
  Response.Write "Not recognized as a date"
End If
%>

This example demonstrates the function, but do not accept arbitrary locale-dependent text as a canonical date in an application that requires one precise input format.

Common errors

Testing the output of DateSerial() with IsDate() will not catch overflow because DateSerial() normalizes dates. Also, IsDate() does not check whether a date falls within a business rule such as minimum age or booking date.

Frequently asked questions

Does IsDate() validate a YYYY-MM-DD form exactly?

Not necessarily. Parsing is influenced by locale and supported date formats. For an exact format, parse and validate its numeric components.

Does IsDate() catch February 31 when DateSerial() is used?

No. DateSerial() normalizes components first. Compare the created date’s parts against the inputs.

Can IsDate() recognize times?

Yes. It can recognize some valid time expressions as well as dates.

What should I use for three separate form fields?

See the complete ASP date-input validator.

Back to top ↑


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer