A form can collect year, month and day separately, validate them on the server and then build a Date value. Avoid constructing an ambiguous string such as yyyy/mm/dd and assuming every server locale will parse it the same way.
<%@ Language=VBScript %>
<% Option Explicit %>
<%
Dim submitted, monthNo, dayNo, yearNo
Dim myDate, validDate
submitted = (Request.Form("todo") = "submit")
If submitted Then
monthNo = Request.Form("month")
dayNo = Request.Form("day")
yearNo = Request.Form("year")
validDate = False
If IsNumeric(monthNo) And IsNumeric(dayNo) And IsNumeric(yearNo) Then
monthNo = CInt(monthNo)
dayNo = CInt(dayNo)
yearNo = CInt(yearNo)
If monthNo >= 1 And monthNo <= 12 And _
dayNo >= 1 And dayNo <= 31 And _
yearNo >= 100 And yearNo <= 9999 Then
myDate = DateSerial(yearNo, monthNo, dayNo)
validDate = (Year(myDate) = yearNo And Month(myDate) = monthNo And Day(myDate) = dayNo)
End If
End If
If validDate Then
Response.Write "<p>Valid date: " & Server.HTMLEncode(CStr(myDate)) & "</p>"
Else
Response.Write "<p>Please enter a valid date.</p>"
End If
End If
%>
<form method="post" action="">
<input type="hidden" name="todo" value="submit">
<label>Month <select name="month" required>
<% Dim m : For m = 1 To 12 %>
<option value="<%=m%>"><%=MonthName(m)%></option>
<% Next %>
</select></label>
<label>Day <select name="day" required>
<% Dim d : For d = 1 To 31 %>
<option value="<%=d%>"><%=d%></option>
<% Next %>
</select></label>
<label>Year <input type="number" name="year" min="100" max="9999" value="2026" required></label>
<button type="submit">Validate date</button>
</form>
The Year/Month/Day comparison after DateSerial() is important because DateSerial() normalizes overflow. For example, February 31 rolls into March instead of raising a validation error.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.