trying to subtract time values can be quite tricky and tedious using the int-time or a time struct like SYSTIME.
I personally like using COleDateTime. This class stores its time internally as a double value.
Consequently the DATE type is a double.
We can convert from COleDateTime to DATE as follows:
COleDateTime oleDtNow = COleDateTime ::GetCurrentTime();
DATE dtNow = (DATE)oleDtNow;
dtNow stores the number of days from a particular reference in the whole number portion while the time is stored in the fraction portion.
The fraction is actually the percentage of seconds in total of the total number of seconds in a day.
Thus if we define the following:
1 2 3
|
const double _1sec = 1.0 / 86400.0;
const double _1min = 60 * __1sec;
const double _1hour = 60 * __1min;
|
Now if we wanted to subtract to times and test if value is less than 20 seconds we can do the following:
1 2 3 4 5 6 7
|
DATE dtFileTime = ...;
DATE dtNow = (DATE)COleDateTime::GetCurrentTime();
if (dtNow - dtFileTime < 20 * _1sec)
{
//remove file
}
|
or you can also simply change the duration as follows:
1 2 3 4
|
if (dtNow - dtFileTime < 3* _1min + 20 * _1sec)
{
//remove file
}
|
The COleDateTime class has a number of constructors that will allow you to convert the file time to it.
One of the constructors you may use is:
COleDateTime oleDtFile(sysTime.wYear, sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);