Cannot perform '<=' operation on System.String and System.DateTime

Hi guys,

I’m trying to filter a DataTable based on a date. However, I keep getting this error message:

Cannot perform ‘<=’ operation on System.String and System.DateTime.

This is what I’m trying to do:
myDataTable.Select("[Completion Date] <= #"+PeriodEnd.ToString +"#").CopyToDataTable

This is an example of a date from my table:
42613 which is 31-08-2016

My PeriodEnd is the following: DateTime.Parse("05/22/2019")

But I just keep getting this error. All suggestions are highly appreciated.

Hi @celfa,
This kind of operation will work with integers as those are number related variables. Have a look here as an examples:

1 Like

Buddy both are of different datataype buddy @celfa
they both should be of type datatime if you want to use <=

Cheers @celfa

Did that work buddy @celfa

@Pablito thanks for your input :slight_smile:
I’ve checked the links you provided, and they are about sorting? I want to actually filter the table.

However, as @Palaniyappan mentioned my data from the dataTable does not seems to be in the “DateTime” format. It is loaded from a Excel sheet where the column is in the “Date” format. Can I somehow change the format for the column in the dataTable?

Buddy @celfa

=======================================
Here you are trying to change the value as string buddy PeriodEnd.ToString, while the PeriodEnd is been parsed to datetime…pass it as it is buddy like just PeriodEnd and i
hope the column Completion Date is of type datetime, so that would work buddy

Kindly try this and let know buddy
Cheers

@Palaniyappan I’m not allowed just to write just PeriodEnd without change it to a string?
My “Completion Date” column is in date format.

hey @celfa

Try this -

myDataTable.Select("[Completion Date] <= '"+PeriodEnd.ToString("MM/dd/yyyy")+"'").CopyToDataTable

Regards…!!
Aksh

Hey @aksh1yadav :wink:

I’ve tried that, but the result is not as expected. The filter does not seem to work. I tried to check the actual column data type with DT.Columns(22).DataType.ToString, and it is in System.Object. So I think that my issue is related to the column type?

So I realised the issue was related to the read range from excel sheet activity. I created a new sheet with the exact values instead of formulars and then it worked like a charm.

Thanks for the input @Palaniyappan @Pablito @aksh1yadav :grinning:

2 Likes

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