DateSerial() creates a real VBScript Date value from separate year, month and day numbers. This is safer than building a locale-sensitive date string when form fields already provide numeric components.
' Incorrect: variables are not evaluated inside #...# date literals
my_date = #my_month, my_day, 1985#
DateSerial(year, month, day)
Dim d1, d2, d3
d1 = 2007
d2 = 2
d3 = 28
Response.Write DateSerial(d1, d2, d3)
Response.Write DateSerial(d1, d2, d3 + 1)
Response.Write DateSerial(d1, d2 - 1, d3)
Response.Write DateSerial(d1 + 5, d2, d3)
Dim d1, d2, d3
d1 = 2008
d2 = 2
d3 = 28
Response.Write DateSerial(d1, d2, d3 + 1)
The result is February 29, 2008.
DateSerial() intentionally normalizes out-of-range components. For example, day 32 rolls into the following month. When validating form input, compare Year(), Month() and Day() of the constructed date with the original numeric inputs.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.