Understanding Dates and Times in VBScript - VBScript’s VT_DATE Specification
(Page 2 of 4 )
Microsoft Visual Basic Scripting Edition uses the VT_DATE specification for working with date and time values. This is a Variant Date type that uses a 64-bit (8 bytes) signed floating point number to represent the number of days that have passed since midnight on a specific day in history, known as an epoch. Hours and minutes are expressed as fractions of a day.
“A specific day in history?”
Yup. Okay, that was a little vague. The VT_Date specification expresses the number of days that have passed since 30 Dec 1899.
“Why that day?”
This is one of those things that is believed to be a bug, but really isn’t. To explain it, you need to become familiar with the standard, so let’s look at some examples.
Let’s assume for once second that the epoch was midnight 31 Dec 2007 instead. As I’m writing this, the current date is 1 Sep 2008. That means that 244 days have elapsed since the epoch day. Further, it’s 3:25 PM. That’s 15 hours and 25 minutes, or 925 minutes that have elapsed since midnight.
We can express today’s date and time as a floating point number like VT_Date. The integer portion of the number is the number of days that have elapsed since the epoch day. There are 244 days that have elapsed. That makes the integer portion equal to 244.
The time is expressed as a decimal fraction of a day. We’ve already shown that 925 minutes have elapsed since midnight. There are 1440 minutes in a day. Simple division shows that 0.642361 days have passed since midnight. Sure enough, at 3:25 PM that’s just about two-thirds of a day.
With all of this in mind, the current date and time would look something like this: 244.642361 if we were using midnight on 30 Dec 2007 as our zero point. This is exactly how the VT_Date specification works—only it works with a zero point much further back in time.
Next: The Significance of 30 Dec 1899 >>
More Windows Scripting Articles
More By Nilpo