I need to compare two files based on datetime. I need to check whether these two files were created or modified with same datetime. I have used this code to read the datetime of files...
string fileName = txtfile1.Text;
var ftime = File.GetLastWriteTime(fileName).ToString();
string fileName2 = txtfile2.Text;
var ftime2 = File.GetLastWriteTime(fileName2).ToString();
Any suggestions?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With