I have an excel file which which have dates in Column “Effective Date”(Sometimes the Date formate is coming as “12/23/2020” and sometimes it comes as 1/2/2020 and sometimes it comes as 2/31/2020), and another Roaster Date(MM/dd/yyyy) is string variable, what i need is to compare all Effective Dates with Roaster Date, and if it Effective Date is on or Before Roaster date, that row should be added to another Sheet. I can do it using Data Table , For Each Rows, .Net Methods, but i want the code using Linq.
(From d In dtData.AsEnumerable
Where now.AddDays(-1).Date = dateTime.ParseExact(d(0).toString,"dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture).Date
Select d).toList
Changed to:
(From d In dtData.AsEnumerable
Let dtp = DateTime.ParseExact(d("Effective Date").toString,Formats, CultureInfo.InvariantCulture, DateTimeStyles.None)
Let ctp = DateTime.ParseExact(strCheckDate,"MM/dd/yyyy", CultureInfo.InvariantCulture)
Where dtp.Date <= ctp.Date
Select d).toList
As you see, the essential parts were already there and required just a little modification