I have date separated with comma eg: 23/March/2024,12/February/2024. I need to loop through the dates and check if it’s in the expected format dd/MMMM/yyyy and return true if all dates are satisfying the criteria. How can I do it with single activity through linq
Hi @dpaktr
datesString = "23/March/2024,12/February/2024"
allDatesValid = datesString.Split(","c).All(Function(dateStr) DateTime.TryParseExact(dateStr.Trim(), "dd/MMMM/yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Nothing))
Hope it helps!!
Hi,
Can you try the following expression?
dt.AsEnumerable.SelectMany(Function(r) r("Column1").ToString.split(","c)).All(Function(s) DateTime.TryParseExact(s,"dd/MMMM/yyyy",System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None,New DateTime))
note: dt is DataTable , this returns true or false for evaluation of Column1
Regards,
Hi @dpaktr
Assign: datesList = inputString.Split(","c).ToList()
Assign: allDatesValid = datesList.All(Function(date) Regex.IsMatch(date.Trim(), "\d{2}/[a-zA-Z]+/\d{4}
"))
Hope this helps you
May I know how to write linq if the input date can be d/MMMM/yyyy or dd/MMMM/yyyy format . Need to check if date is in above format and greater than today and return true or false
HI,
Can you share specific input and expected output?
If you need array of boolean as result, the following will work.
strDate.Split(","c).Select(Function(s) DateTime.ParseExact(s,"d/MMMM/yyyy",System.Globalization.CultureInfo.InvariantCulture)>DateTime.Today).ToArray
Sample
Sample20240402-2.zip (2.6 KB)
Regards
My input can be like 12/March/2024,3/April/2024. Need to return true if all dates are in either of the two format (dd/MMMM/yyyy or d/MMMM/yyyy) and greater than today. Return false if any date is not satisfying above two conditions
Hi,
How about the following?
strDate.Split(","c).All(Function(s) DateTime.ParseExact(s,"d/MMMM/yyyy",System.Globalization.CultureInfo.InvariantCulture)>DateTime.Today)
Sample
Sample20240402-2 (2).zip (2.5 KB)
Regards,


