Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I substract two FILETIMEs?

Tags:

c++

windows

I'm trying to get the elapsed times in miliseconds in windows. The only way I've found to do this is to get the number of 100 nanoseconds since 1601 with the FILETIME structure. But the FILETIME structure stores the value in two variables, and I want to know how I can substract two of this structures, divide them by 10000 (to get the miliseconds) and store the result in a single variable I'm using c++ with visual studio 2008 express edition

like image 301
XaitormanX Avatar asked Apr 04 '12 10:04

XaitormanX


People also ask

How do you subtract one time from another?

Explanation: To subtract time, subtract the minutes then subtract the hours. Since we can't have negative minutes, add 60 to the minutes and subtract 1 from the hours (60 minutes = 1 hour).

How do you subtract two date columns?

Calculate the difference in days Select cell D2, which is the first blank cell in the Duration column. Type =C2-B2, and then press RETURN . Excel displays the result as the number of days between the two dates (104). Select cell D2.

How do you calculate time duration?

Calculate the duration between two times First, identify the starting and an ending time. The goal is to subtract the starting time from the ending time under the correct conditions. If the times are not already in 24-hour time, convert them to 24-hour time. AM hours are the same in both 12-hour and 24-hour time.


1 Answers

Read the documentation of FILETIME:

It is not recommended that you add and subtract values from the FILETIME structure to obtain relative times. Instead, you should copy the low- and high-order parts of the file time to a ULARGE_INTEGER structure, perform 64-bit arithmetic on the QuadPart member, and copy the LowPart and HighPart members into the FILETIME structure.

And there you have your single number, too (QuadPart of the ULARGE_INTEGER structure).

like image 64
Joey Avatar answered Oct 04 '22 20:10

Joey