VBScript: Final Date Functions - Timer...It Has Its Eye On You (Page 4 of 5 )
The Timer() function returns the amount of seconds since 12:00 am (midnight). You can also perform calculations based on the Timer() function, such as seeing how many hours or minutes have passed. Here it is in code:
<html>
<body>
<script type="text/vbscript">
document.write("The amount of seconds since 12 am: ") & (Timer) & "<br />"
document.write("The amount of minutes since 12 am: ") & (Timer/60) & "<br />"
document.write("The amount of hours since 12 am: ") & (Timer/3600) & "<br />"
</script>
</body>
</html>
Which gives us the result:
The amount of seconds since 12 am: 40718.42
The amount of minutes since 12 am: 678.6404
The amount of hours since 12 am: 11.31067
Cereal Time
I just scarfed down a box of Apple Jacks, probably the best cereal on the planet. I don't know why Cookie Crisp doesn't have the foresight to make those mini boxes of cereal. I mean they would have total market domination if they did, just from me alone.
The TimeSerial() function returns the time for an hour, minute, and second that you specify. It is comprised of three sections, separated by commas. The first is for the hour, the second is for minutes, and the third is for seconds. You can also perform math on these sections, as you will see below:
<html>
<body>
<script type="text/vbscript">
document.write(TimeSerial(10,8,32)) & "<br />"
document.write(TimeSerial(22,18,59)) & "<br />"
document.write(TimeSerial(0,0,0)) & "<br />"
document.write(TimeSerial(12,0,0)) & "<br />"
document.write(TimeSerial(22-14,18+3,12*3)) & "<br />"
</script>
</body>
</html>
And as always, our result:
10:08:32 AM
10:18:59 PM
12:00:00 AM
12:00:00 PM
8:21:36 AM
Note that this works off of military time, so 12, 0, 0 equals 12:00:00 PM and 0,0,0 equals 12:00:00 AM.
Next: The TimeValue() Function >>
More BrainDump Articles
More By James Payne