Filter By date in Excel in the same sheet

Hello!!!

Today, im trying to filter by date In Excel in the same sheet Using this LinQ:

(From z In DT1 Where Not String.IsNullOrEmpty(z(18).ToString) And Convert.ToDateTime(z(18).ToString) > Date.Now.AddDays(-41)Select z).CopyToDataTable

The date is in the column 19 BUt is returning this message:

The string was not recognized as a valid DateTime. There is an unknown word starting at index 0

How can i improve this LinQ??

What is the format of date in z(18) ?

Mr. @Vivek_Arunagiri Hi

The format is: YYYY-MM-DD

Then use (From z In DT1 Where Not String.IsNullOrEmpty(z(18).ToString) And DateTime.ParseExact(z(18).tostring, “yyyy/MM/dd”,System.Globalization.CultureInfo.InvariantCulture) > Date.Now.AddDays(-41)Select z).CopyToDataTable

1 Like

Now show me this error Assign: String was not recognized as a valid DateTime
And tell mi that Expected an ‘)’ i’m gonna try find a solution for that ‘)’ … what do you thinks Mr.Vivek?

Got it… you need to give “-” instead of “/”

(From z In DT1 Where Not String.IsNullOrEmpty(z(18).ToString) And DateTime.ParseExact(z(18).tostring, “yyyy-MM-dd”,System.Globalization.CultureInfo.InvariantCulture) > Date.Now.AddDays(-41)Select z).CopyToDataTable

It keep showing an " ‘)’ Expected"

Im searching for the ‘)’ to put it…maybe in the where

Thanks for always reply!!!
Regards

Try

(From z In DT1 Where (Not String.IsNullOrEmpty(z(18).ToString) And DateTime.ParseExact(z(18).tostring, “yyyy-MM-dd”,System.Globalization.CultureInfo.InvariantCulture) > Date.Now.AddDays(-41)).Select(z).CopyToDataTable

1 Like

Nope, now i hate the YYYY-MM-DD format jaja.

its missing the first “(” close “)”
Guess its supposed to be like this
(From z In DT1 Where (Not String.IsNullOrEmpty(z(18).ToString) And DateTime.ParseExact(z(18).tostring, “yyyy-MM-dd”,System.Globalization.CultureInfo.InvariantCulture) > Date.Now.AddDays(-41)).Select(z)).CopyToDataTable

2 Likes

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