I have list(of string) in which contains the folder names as dates ‘MM.dd.yy’ and i need to find the latest date from this list
2 Likes
Try with the below steps.
- Create a variable as “lstDates” as List(Of DateTime) datatype
- Then use assign activity to convert your datetime string list to List(Of DateTime)
lstDates= yourListStringDate.[Select](Function(x) DateTime.ParseExact(x, “MM…dd.yy”, Nothing)).ToList() - You can get min date → lstDates.Min()
- You can get maxdate → lstDates.Max()
This will return as datetime datatype
Some sample values would be helpfully. Give a try on following:
myMaxDate | DateTime =
(From x in YourList
let m = System.Text.RegularExpressions.Regex.Match(x, "\d{2}\.\d{2}\.\d{2}")
Where m.Success
Let dp = DateTime.ParseExact(m.Value, "MM.dd.yy", System.Globalization.CultureInfo.InvariantCulture)
Order by dp.Date
Select v = dp).Last()
My actual process is i have a path in which there are several folders named with dates mm.dd.yy i need to get only the latest date folder (excluding the nondate folders)
(
Note:- Cant find through modified date because all folders are created same day itself)
LINQ should work for this including defensive handling of non dates. Had you tried?
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.