Last post Nov 08, 2019 02:10 AM by jiadongm
Nov 07, 2019 07:36 PM|denkyira|LINK
I am trying to get a count of number of days between two days inside Linq Select new query but I am getting an output like this -00:03:42.2470000.
Below is my code. Any help will be appreciated.
var dayInProcs = DateTime.Today;
var exportToexcel = data.admin.AsQueryable()
.Include(x => x.employees.contractors)
.Include(x => x.employees.contractorRoles)
.Where(x => x.employees.contractors.Id == 60);
var roles = exportToexcel.Select x => new
delivered = x.ArrivalDate - x.SortedDate, // I want to get 20 here
DaysInProcess = x.ArrivalDate - dayInProcs // And 5 here
Nov 07, 2019 07:57 PM|DA924|LINK
Link-2-Entities is probably not going to let you do anything else, becuase Link-2-Entities generates T-SQL to submit for execution against the database tables and sometimes it will throw exception when functions are used in the Linq such as true date functions..
My advise is to get the results out with normal dates and disconnect the EF connection, which makes the result disconnected. You will be using Linq-2-Object to query the result, and you could use true date functions in C# for date calculations you are
trying to accomplish.
Nov 07, 2019 10:46 PM|bruce (sqlwork.com)|LINK
depending on if you are 4.* or core, you can use SqlFunctions (4.* only):
Nov 08, 2019 02:10 AM|jiadongm|LINK
You can use (EndDate - StartDate).TotalDays to calculate days between two
DateTime type values.