Cannot perform 'Like' operation on System.DateTime and System.String.- for Assign

Hi All,

I am trying to get the current date from the input excel and write them to the another excel with the below query,

Input_dt.select(“[Transoft_Processing_Date_Time]like '%”+now.ToShortDateString+“%'”).CopyToDataTable

But getting the error as below,

This is the input excel …where the date column I selecting,

input excel- date

Can I please know how it can be resolved.

Thanks in advance.

it looks like that it takes on the left side the dateTime and on the right side it has the string

give a try on:
Input_dt.select(“[Transoft_Processing_Date_Time] = #”+now.toString()+“#”).CopyToDataTable

the surrounding # indicates that it is a date

grafik

https://www.csharp-examples.net/dataview-rowfilter/

it is saying no data rows.

@sushmitha.e
CopyToDataTable will throw this error when the filter result is empty

it can be handled as by following:
Input_dt.select(“[Transoft_Processing_Date_Time] = #”+now.toString()+“#”).ToList

then check the returned row count similar to
grafik

the reason that the filter result is empty can be:

  • there is no row that is matching the filter expression
  • there is a problem with the select - just inspect the datatable contents during a debugging

But today’s date is there in Input Excel…

image

so, why it is given again the output as no data rows.

Have a look here on another approach, but handling multiple dateformats:

DT_FilterByDate_2Formats.xaml (10.6 KB)

Ok sure, thanks.

@sushmitha.e

I had a closer look on it. The time Info confused and it seems that it was blocking the rows.
From the datatable the particular time info was compared with that one from #…+now.toString(… # or 00:00:00 in some scenarios.

dtData.Select(“[Column1] >= #”+now.toString(“MM/dd/yyyy”)+“# And [Column1] <= #”+now.AddDays(1).toString(“MM/dd/yyyy”)+“#”).ToList is working

find demo xaml here:
DTSelect_TodaysDate.xaml (7.4 KB)

Handling the different formats I would say that with the first shared xaml you will have more control on it