Microsoft KB Archive/297463

= PRB: VariantTimeToSystemTime and SystemTimeToVariantTime Functions Ignore Milliseconds Value of System Time =

Article ID: 297463

Article Last Modified on 7/18/2001

-

APPLIES TO


 * Microsoft Win32 Software Development Kit (SDK) 4.0

-



This article was previously published under Q297463



SYMPTOMS
When you use the VariantTimeToSystemTime function to convert variant time to system time and the SystemTimeToVariantTime function to convert system time to variant time, the milliseconds value appears as zero or is ignored.



CAUSE
SystemTimeToVariantTime (which uses the VarUdateFromDate function) and VariantTimeToSystemTime (which uses the VarDateFromUdate function) are not resolute up to milliseconds.



RESOLUTION
Do not use SystemTimeToVariantTime, VariantTimeToSystemTime, VarUdateFromDate, or VarDateFromUdate if you require millisecond resolution.

Beginning with Microsoft Windows NT 4.0 Service Pack 4 (SP4), Windows 95 with Distributed Component Object Model (DCOM) 1.2, and Windows 98, Automation now supports passing user-defined types (UDTs) in variants and safearrays of user-defined types as arguments to methods. This allows methods to return UDTs and allows programmers of Automation controllers (Automation clients) to call methods that require pointers to structures. As an alternative to using the above-mentioned functions, you can wrap the SYSTEMTIME structure to a user and pass the user-defined data type to automation interfaces.

For more information on user-defined data types, see the following Microsoft Web site:

http://msdn.microsoft.com/library/psdk/automat/chap12_3rcj.htm



STATUS
This behavior is by design.



MORE INFORMATION
To reproduce this problem, replace the code that is generated for a standard console application with the following code:
 * 1) include &quot;stdafx.h&quot;
 * 2) include 
 * 3) include 

int main(int argc, char* argv[]) {   SYSTEMTIME stNow1, stNow2; GetSystemTime(&stNow1); stNow2 = stNow1; // Set different values for milliseconds. stNow1.wMilliseconds =10; stNow2.wMilliseconds =0; printf(&quot;SystemTime with Milliseconds:\n&quot;       &quot;Hours: %d, Minutes: %d, Seconds: %d, Milliseconds: %d\n&quot;,        stNow1.wHour, stNow1.wMinute, stNow1.wSecond, stNow1.wMilliseconds); printf(&quot;SystemTime without Milliseconds:\n&quot;       &quot;Hours: %d, Minutes: %d, Seconds: %d, Milliseconds: %d\n&quot;,        stNow2.wHour, stNow2.wMinute, stNow2.wSecond, stNow2.wMilliseconds); double dTime1,dTime2; SystemTimeToVariantTime (&stNow1,&dTime1); SystemTimeToVariantTime (&stNow2,&dTime2); printf(&quot;VariantTime from SystemTime with Milliseconds: &quot;       &quot;%0.9f\n&quot;, dTime1); printf(&quot;VariantTime from SystemTime without Milliseconds: &quot;       &quot;%0.9f\n&quot;, dTime2); printf(&quot;(Both of the above values are same, which shows that the\n&quot; &quot;SystemTimeToVariantTime conversion routine ignores Milliseconds)&quot;); // Calculate a variant time with milliseconds. // For example, .840845486 portion of 37085.840845486 corresponds // to 20 hours, 10 minutes, 49 seconds, and 50 milliseconds. dTime1 = 37085.840845486; printf(&quot;\n\nVariantTime with Milliseconds: %0.9f \n&quot;, dTime1); printf(&quot;SystemTime corresponding to above variant date:\n&quot;       &quot;Hours: 20, Minutes: 20, Seconds: 49, Milliseconds: 50\n&quot;); SYSTEMTIME stCheck; VariantTimeToSystemTime(dTime1,&stCheck); printf(&quot;Value of Milliseconds in SystemTime after conversion: %d\n&quot;,       stCheck.wMilliseconds ); printf(&quot;(The above value shows that the VariantTimeToSystemTime\n&quot; &quot;conversion routine ignores Milliseconds)\n\n&quot;); return 0; }

Keywords: kbinfo kbapi kbprb KB297463

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.