locked
How to get .txt file between 2 dates using c#? RRS feed

  • Question

  • I am writing console application to get all .txt file between 2 date.

    Below is my code.

    DateTime endTime = DateTime.Now;
                DateTime starttime = Convert.ToDateTime("8/20/2016 12:02:44 PM");
                var filesBetweenDates = Directory.GetFiles(filePath, "*.txt", SearchOption.AllDirectories).Where(f => new FileInfo(f).CreationTime > starttime && new FileInfo(f).CreationTime < endTime);

    but its not returning any file. when I use only :-

    var filesBetweenDates = Directory.GetFiles(filePath, "*.txt", SearchOption.AllDirectories);

    without where condition then working file. please help me in this 

    Thanks,

    Monday, August 29, 2016 7:21 AM

Answers

  • Take a look at this...

     var filePath = @"c:\users\s.russo";
    
                DateTime endTime = DateTime.Now;
                DateTime starttime = Convert.ToDateTime("8/20/2016 12:02:44 PM");
                DirectoryInfo di = new DirectoryInfo(filePath);
                var filesBetweenDates = di.GetFiles("*.txt", SearchOption.AllDirectories).Where(f => f.CreationTime > starttime && f.CreationTime < endTime);
    


    Regards,
    Bubu
    http://zsvipullo.blogspot.it

    Please mark my answer if it helped you, I would greatly appreciate it.

    Monday, August 29, 2016 8:07 AM