views:

257

answers:

1

Now() in VBScript appears to return time in 10,000,000th of a second precision when called as CDbl(Now()). In attempting to use this to write a more accurate implementation of now which returns CIM_DATETIME format I found that in VBScript, despite being particularly precise, is not very accurate with the time only updating once per second. This can be demonstrated by watching the output from what follows:

i = 0
While i < 50
    gnow = Cdbl(now) 
    result = (gnow - Int(gnow))
    WScript.Echo CDate(gnow)
    WScript.Echo "Iteration " & i & ": " & result
    WScript.Sleep(100)
    i = i + 1
Wend

The question I'm now trying to answer is, given a VBScript that runs for less than a second which calls Now(), what time will be returned by Now()? Is it the time that the script interpreter started, the time when Now() was called, or something else?

A: 

It looks like it will be the time the "Now()" method was called accurate to the second. It's still a normal method invocation.

David
David: I'm specifically trying to do greater than one second accuracy. The precision for this is clearly there, but I'm needing a better understanding of how the number that Now() returns is determined.
You are seeing the precision of the double data type which doesn't match the precision of the "Now()" function.
David
Take a look at the "Timer" function instead. It looks like it gives sub-second resolution.
David