I am trying to understand why the following function does not work.
public IEnumerable<LogFile> GetLogs(string directory, DateTime start, DateTime end) { DirectoryInfo di = new DirectoryInfo(directory); return di.GetFiles("*debug.log").Where(f => f.LastWriteTime > start && f.LastWriteTime <= end).Select(f => new LogFile(f.FullName)); }
Why (f.LastWriteTime <= end) second comparison (f.LastWriteTime <= end) omit the specified end date?
The first comparison (f.LastWriteTime > start) includes the specified start date.
For the sample, if I set the start date to 1/4/2013 and the end date to 1/8/2013, the function returns files with the following dates:
1/4/2013, 1/5/2013, 1/6/2013, 1/7/2013
It will not include 1/8/2013, despite using <= in the code.
source share