How to compare two files based on datetime?
Don't call ToString()
on the DateTime
values returned by GetLastWriteTime()
. Do this instead:
DateTime ftime = File.GetLastWriteTime(fileName);
DateTime ftime2 = File.GetLastWriteTime(fileName2);
Then you can just compare ftime
and ftime2
:
if (ftime == ftime2)
{
// Files were created or modified at the same time
}
Well, how about doing
ftime == ftime2
? No need for the ToString though, better just compare DateTimes as-is.