i have a SYSTEMTIME (timeTo) with a date/time in the future (say, a week from today), im trying to find out the difference between timeTo and the current time (timeFrom) as a fraction. something like: 1.99 days.
i read through MSDN and found out that i cant use the values in the structure:
i did all that, heres the code i have:It is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times. Instead, you should
· Convert the SYSTEMTIME structure to a FILETIME structure.
· Copy the resulting FILETIME structure to a LARGE_INTEGER structure.
· Use normal 64-bit arithmetic on the LARGE_INTEGER value.
the problem is, the difference between the 2 times is never > 0, even though im 100% sure that timeTo > timeFrom.Code:float CalculateTimeLeft(SYSTEMTIME timeTo) { LARGE_INTEGER nFrom, nTo; __int64 n64From, n64To, nDiff; SYSTEMTIME timeFrom; FILETIME fileTimeTemp; float fReturn = 0.0f; GetSystemTime(&timeFrom); // current time SystemTimeToFileTime(&timeFrom, &fileTimeTemp); nFrom.HighPart = fileTimeTemp.dwHighDateTime; nFrom.LowPart = fileTimeTemp.dwLowDateTime; n64From = (__int64)&nFrom; // timeFrom as an int SystemTimeToFileTime(&timeTo, &fileTimeTemp); nTo.HighPart = fileTimeTemp.dwHighDateTime; nTo.LowPart = fileTimeTemp.dwLowDateTime; n64To = (__int64)&nTo; // timeTo as an int nDiff = n64To - n64From; // difference should be positive if (nDiff > 0) // it never makes it here { cout << "ndiff > 0" << endl; fReturn = nDiff / 1000.0f / 60.0f / 60.0f / 24.0f; // not sure of the math yet } else { cout << "ndiff <= 0" << endl; } return fReturn; }
also, this is the first time im working with LARGE_INTEGERS, so i convert them to 64-bit ints so i can use them as normal ints.