Linq to Get Items where Column Date's month is equal to a variable

I am trying to use this Linq DT_Orders.AsEnumerable.Where(Function(x)x("OrderStatus").ToString.Equals("Done") AND x("Date").Contains(CurrentMonth)).CopyToDataTable. CurrentMonth Variable a String that Contains current month in “MMM” Format, same as my months in the Datatable
But it says Option Strict on late Binding.
It would be better if I could get the Month from the Column directly, so that I could use .Equals instead of .Contains. I hope you can help me thank you.

Hi @Archie

Hope the below expression would help you resolve this

Usually month can be e
M - 2
MM - 02

So MMMM is correct

But change the expression like this

DT_Orders.AsEnumerable.Where(Function(x)x(“OrderStatus”).ToString.ToUpper.Contains(“DONE”) AND CurrentMonth.ToString.ToUpper.Contains(x(“Date”).ToString.ToUpper)).CopyToDataTable

CurrentMonth = Datetime.Now.ToString(“MMMM”)

Cheers @Archie

How the month csn be in MMMM format?

It must b MM

Can you show us the data you are trying to convert?

Hello :smiley:

Have updated the previous comment
Pls check @Archie

My bad, it is in MMM Format. My Date in DT are formatted like “August 12, 2021”. I set the Current Month to “MMM” Format to get the month and use .contains to DT, to filter it by the current month

In that case mention like this

DT_Orders = DT_Orders.AsEnumerable.Where(Function(x)x(“OrderStatus”).ToString.ToUpper.Contains(“DONE”) AND x(“Date”).Tostring.ToUpper.Contains(CurrentMonth.ToString.ToUpper)).CopyToDataTable

X(“Date”).ToString is “August 12, 2021”
CurrentMonth is MMM that is Aug

Cheers @Archie

1 Like

Thanks! It worked for me.

1 Like

Glad @Archie

1 Like

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