How to Select records between two dates using linq
I have a datatable in which I have 2 date columns i.e fromDate and toDate of type string.
I am trying to get the data between by passing two date parameter values with datetime conversion but it is not working.
I am filtering the datatable using linq.
Kindly help me getting my code work below is my code.
Any suggestions will be appriciated.
string fromDt = Convert.ToDateTime(txtFromDate.Text).ToString("dd/MM/yyyy").Replace('-', '/');
string toDt = Convert.ToDateTime(txtFromDate.Text).ToString("dd/MM/yyyy").Replace('-', '/');
db.datatable = db.datatable.AsEnumerable().Where(x => Convert.ToDateTime(x.Field<string>(ddlSelect)) >= Convert.ToDateTime(fromDt) && Convert.ToDateTime(x.Field<string>(ddlSelect)) <= Convert.ToDateTime(toDt)).CopyToDataTable();