Assign: Cannot perform '=' operation on System.Double and System.DateTime

I have Column named Invoice date and I want to filter Date to get all dates that equal to current date

I tried this But it does’t work.

Excel_DataTable.Select(“[InvoiceDate] = #”+ FilterDate.ToString +“#”).CopyToDataTable

The date come like this from the auto generated excel file.

Please assist.

Hi @Malusi_Ngubane,

Can you please share the version before filtering? In addition, can you write the value of the variable you filtered?


The screen short you see is the original date format before I try to filter, So what challenging me is to be able to convers that format in to the normal date format that I can then be able to apply filters

Can you get the date value when you click on a cell in this field? Can you share the excel?

Yes, when I click on the cell I can see the date, Please find below sample file

Book1.xlsx (8.1 KB)

you can try to reformat the cell before read range

checking your excel, after read range on what it is the result after read range:

we do see OAdate doubles (makes sense to the exception) which we can be handled by

Maybe filtering with following LINQ will work

dtFiltered =

(From d in YourDataTableVar.AsEnumerable
let dp = DateTime.FromOADate(CDbl(d("InvoiceDate").toString.trim))
Where dp.Date = YourFilterDateTime.Date
Select r = d).CopyToDataTable
1 Like

When we read the table, it looks like this, so when filtering, it is necessary to comply with this format.

You can only give the date range by doing contains in the filter, but the date format should be “MM/dd/yyyy”.




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