Reputation: 646
I want to remove only the seconds part of the output which comes as my ActualWorkedHours variable [HH:mm:ss].
This is my C# code:
ActualWorkedHours =(shiftAttendanceBo.ActOutDateTime.Value.Subtract(shiftAttendanceBo.ActInDateTime.Value).Duration().ToString()
How can I do this?
Upvotes: 0
Views: 991
Reputation: 2507
TimeSpan ts = new TimeSpan(10,30,15);
Console.WriteLine(ts.ToString(@"hh\:mm"));
Upvotes: 0
Reputation: 322
TimeSpan ts = (shiftAttendanceBo.ActOutDateTime.Value.Subtract(shiftAttendanceBo.ActInDateTime.Value).Duration()
ActualWorkedHours = (ts - new TimeSpan(0, 0, ts.Seconds)).ToString();
Upvotes: 0
Reputation: 12797
If you are on .Net 4, then you can use ToString(@"hh\:mm")
Upvotes: 2