Click here to Skip to main content
16,015,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

What I have tried:

<pre>
              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
               }).Distinct()),
Posted
Updated 7-Nov-19 8:44am

1 solution

Take a look at code below:

C#
DateTime ArrivalDate = new DateTime(2019,11,7);
DateTime SortedDate = new DateTime(2019,10,18);

int daysDiff = (ArrivalDate - SortedDate).Days;
//returns 20 ;)


For further details, please see: TimeSpan Struct (System) | Microsoft Docs[^]
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 7-Nov-19 18:32pm    
5ed!
Maciej Los 8-Nov-19 2:08am    
Thank you.
Member 1283347 8-Nov-19 8:28am    
Hi Thanks for your solution but this does not work in Entity Frame work. I have solved it be using DbFunctions.DiffDays

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900