Linq latest date after today

Hello all,

I have found a linq command in the forum which gives me the last date, this works great. What is new is that I want the last date, which is after today. Meaning if the oldest date is < than today, then take the next date after today. who can help me with this?

for example:

|01.06.2023|45078| = last
|21.08.2023|45159| = Today
|24.08.2023|45162| = need
|11.11.2023|45241|
|24.12.2023|45284|

(From row In DtForDate Order By DateTime.ParseExact(row.Item(“Liefertermin”).ToString, “dd.MM.yyyy”,
System.Globalization.CultureInfo.InvariantCulture) Descending Select row).Last()(“Liefertermin”).ToString

Hi @NHoe

try this Linq-Query

(From row In DtForDate 
    Where DateTime.ParseExact(row.Item(“Liefertermin”).ToString, “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture) > today
    Order By DateTime.ParseExact(row.Item(“Liefertermin”).ToString, “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture) 
    Select DateTime.ParseExact(row.Item(“Liefertermin”).ToString, “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture)).FirstOrDefault()

Thank you, it works with that

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.