Comparing a datetime string in datatable with a constant date

in a datatable I have a field with datetime string (like “2026-04-16T00:00:00”)
in a datatablefilter i want to filter only rows that have a date that is greaterthan or equal to Today (or another date)
I tried different variants of:
dt_Mdw.AsEnumerable().Where(Function(r) datetime.parse(r(“Date”).ToString) >= datetime.parse(Today) )
but all to no effect
how to syntax this?

Another option (in variants) I tried is using dt_Mdw.AsEnumerable().Where(Function(r) datetime.compare(datetime.parse(r(“Date”).ToString),datetime.parse(Today) ) >= 0 )
but also to no effect

Ah, I have an addition that appearantly is frustrating. The date can be a NULL value. and a NULL value frustrates date comparisson
I wil have to get around this. Actually the total query would be (Date >= today or Date is nullorempty)

so, this works. But it has got to be easier?
dt_Mdw.AsEnumerable().Where(Function(r) datetime.compare(convert.ToDateTime(if(string.isnullorempty(r(“Date”).ToString),“9999-01-01”,r(“Date”).ToString)),Today) >0 ).ToArray.CopyToDatatable

Hi,

How about the following?

dt_Mdw.AsEnumerable().Where(Function(r) String.IsNullOrEmpty(r("Date").ToString()) OrElse DateTime.Parse(r("Date").ToString()).Date >= Today).CopyToDataTable()

Regards,

@Luke69 You’re very close :slightly_smiling_face: The issue is happening because you’re converting the DateTime back to string (ToString) and then comparing it.

Instead, compare DateTime with DateTime directly.

Try this:

dt_Mdw.AsEnumerable().
Where(Function(r) DateTime.Parse(r("Date").ToString) >= DateTime.Today)

If your datetime format is fixed (like yyyy-MM-ddTHH:mm:ss), it’s even better to use ParseExact:

dt_Mdw.AsEnumerable().
Where(Function(r) DateTime.ParseExact(r("Date").ToString, "yyyy-MM-ddTHH:mm:ss", System.Globalization.CultureInfo.InvariantCulture) >= DateTime.Today)

Thanks for the thinking with me, and the lessons therein. it works and I have enriched my limited skills. there is not particularly 1 solution but there is a lessons in all.