Assume the model mapping to your database table is called "WorkTime" as below:
public class WorkTime
{
public int Id { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
Let's extend it :
public class WorkTime
{
public int Id { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public TimeSpan WorkTimeSpan => EndTime - StartTime;
public string Days => string.Format("{0:%d}", WorkTimeSpan);
public string Hours => string.Format("{0:%h}", WorkTimeSpan);
public string Minutes => string.Format("{0:%m}", WorkTimeSpan);
public string Seconds => string.Format("{0:%s}", WorkTimeSpan);
}
Test it:
[TestMethod]
public void Test_WorkTime()
{
var workTime = new WorkTime
{
Id = 1,
StartTime = new DateTime(2021, 11, 3, 21, 23, 33),
EndTime = DateTime.Now
};
Console.WriteLine($"{workTime.Days} days,{workTime.Hours} hours,{workTime.Minutes} minutes,{workTime.Seconds} seconds.");
//The output : 1 days,0 hours,12 minutes,46 seconds.
}
Now you can binding the "Days","Hours","Minutes","Seconds" to your DataGridView.
If you calculate the total, you can subtract the minimum start time from the maximum end time , then get the TimeSpan.
Enjoy Programing!!!
Please refer to TimeSpan : TimeSpan