VBScript DateSerial function

VBScript DateSerial

VBScript DateSerial() Function returns a date when specified day, month and year are passed to it as parameters.

Syntax

DateSerial(year,month,day)

Parameter Description

ParameterRequired?Explanation
yearRequiredA number between 100 and 9999 or a numeric expression
monthRequiredIt is number having range from 1 to 12.
dayRequiredIt is number having range from 1 to 31.

Year value should be -

  1. Values between 30 and 99 is considered as years between 1930 to 1999.
  2. All the remaining years should be used by writing complete four-digit year.

VBScript Examples:

Example 1 : Year in two digit

<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
document.write("Date in 2 Digit Number from 00 to 29" & "<br />")
document.write(DateSerial(00,5,21)   & "<br />")
document.write(DateSerial(01,5,21)   & "<br />")
document.write(DateSerial(04,5,21)   & "<br />")
document.write(DateSerial(28,5,21)   & "<br />")
document.write(DateSerial(29,5,21)   & "<br />")
document.write("Date in 2 Digit Number from 30 to 99" & "<br />")
document.write(DateSerial(30,5,21)   & "<br />")
document.write(DateSerial(31,5,21)   & "<br />")
document.write(DateSerial(32,5,21)   & "<br />")
document.write(DateSerial(97,5,21)   & "<br />")
document.write(DateSerial(98,5,21)   & "<br />")
document.write(DateSerial(99,5,21)   & "<br />")
</script>
</body>
</html>

Output :

After running above script in IE we will get following output -

Date in 2 Digit Number from 00 to 29
5/21/2000
5/21/2001
5/21/2004
5/21/2028
5/21/2029
Date in 2 Digit Number from 30 to 99
5/21/1930
5/21/1931
5/21/1932
5/21/1997
5/21/1998
5/21/1999

Example 2 : Year in four digit

Now consider the following example -

<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
document.write(DateSerial(1198,5,21)   & "<br />")
document.write(DateSerial(1298,5,21)   & "<br />")
document.write(DateSerial(1398,5,21)   & "<br />")
document.write(DateSerial(1498,5,21)   & "<br />")
document.write(DateSerial(1598,5,21)   & "<br />")
</script>
</body>
</html>

Output :

After running above script in IE we will get following output -

5/21/1198
5/21/1298
5/21/1398
5/21/1498
5/21/1598