VBScript: More Fun with the Date Functions - What Day is it Anyway? (Page 4 of 6 )
If we want to know which day of the month it is (represented by a value ranging from 1-31), we can use the Day() function, like so:
<html>
<body>
<script type="text/vbscript">
document.write("Today's date is: ") & Date & ("<br />")
document.write("The day of the month is ") & Day(Date)
</script>
</body>
</html>
This results in the printout:
Today's date is: 12/28/2008
The day of the month is 28
Formatting the Date/Time with the...(drum roll please) FormatDateTime() Function
If you want to specify how your date/time looks, one way to do so is with the FormatDateTime() function. There are five different formats you can use, starting with 0 and working through to number 4. Here they are in code:
<html>
<body>
<script type="text/vbscript">
document.write("Today's date is: ")
document.write(FormatDateTime(Date(),4))
document.write("<br />")
document.write("Today's date is: ")
document.write(FormatDateTime(Date(),3))
document.write("<br />")
document.write("Today's date is: ")
document.write(FormatDateTime(Date(),2))
document.write("<br />")
document.write("Today's date is: ")
document.write(FormatDateTime(Date(),1))
document.write("<br />")
document.write("Today's date is: ")
document.write(FormatDateTime(Date()))
document.write("<br />")
</script>
</body>
</html>
And the result:
Today's date is: 00:00
Today's date is: 12:00:00 AM
Today's date is: 1/28/2008
Today's date is: Monday, January 28, 2008
Today's date is: 1/28/2008
Next: Day, Month, Year, Hour, Minute, Second >>
More BrainDump Articles
More By James Payne