VBScript: More Fun with the Date Functions - Serial Dating
(Page 3 of 6 )
The DateSerial...well it's hard to explain exactly what it does, so I am just going to show you. The syntax is DateSerial(year,month,day). Here we go:
<html>
<body>
<script type="text/vbscript">
document.write("I was born on: ")
document.write(DateSerial(1977,4,22) & "<br /")
</script>
</body>
</html>
Which results in:
I was born on: 4/22/1977
You can also do this:
<html>
<body>
<script type="text/vbscript">
document.write("I was born on: ")
document.write(DateSerial(2007-30,12-8,4+18) & "<br /")
</script>
</body>
</html>
This also results in:
I was born on: 4/22/1977
Valuing Your Date
The DateValue returns a value that is a Date type. Here it is in action:
<html>
<body>
<script type="text/vbscript">
document.write(DateValue("28-Nov-07") & "<br />")
document.write(DateValue("28-Nov"))
</script>
</body>
</html>
The result:
11/28/2007
11/28/2007
You will note that if you leave the year portion out of the statement, it will use the systems year.
Next: What Day is it Anyway? >>
More BrainDump Articles
More By James Payne