I am calculating time difference between two dates with format:
Hour:Minutes:Seconds
Right now i am getting output like this with the following input:
StartDate=2016-06-29 15:52:32.360
EndDate=2016-06-29 15:52:36.970
Output: 0 : 0 : 4
But i want to get double digit output in time :
Expected Output: 00 : 00 : 04
Input:
StartDate=2016-06-29 15:52:32.360
EndDate=2016-06-29 15:53:36.970
Expected output: 00 : 01 : 04
This is my code:
public class Attendance
{
public int Id { get; set; }
public Nullable<System.DateTime> StartDateTime { get; set; }
public Nullable<System.DateTime> EndDateTime { get; set; }
}
var query = (from t in context.Attendance
select new
{
TotalTime =SqlFunctions.DateDiff("s",t.StartDateTime,t.EndDateTime) /3600 + " : "
+ SqlFunctions.DateDiff("s", t.StartDateTime, t.EndDateTime) % 3600 / 60
+ ": " + SqlFunctions.DateDiff("s", t.StartDateTime, t.EndDateTime) % 60,
}).tolist();
Note:I dont want to do like below:
var query = (from t in context.Attendance.toList().
select new
{
//code to calculate time difference and format time
}).tolist();