Hi,
First get the hour1 in a string and minutes an another string.
Example:
string hour1= 12,
string hour1minutes = 00,
Then use timespan for this
Timespan tshour1 = new timespan(hour1,hour1minutes,00)
Then declare a string called
FirstTotalHrs = Math.Floor(tshour1 .TotalHours) + ":" + (tshour1 .Minutes < 10 ? "0" + tshour1 .Minutes : tshour1 .Minutes.ToString());
Like follow the above steps to get the second time(i.e., hour2)
string hour2= 12,
string hour2minutes = 00,
Then use timespan for this
Timespan tshour2 = new timespan(hour2,hour2minutes,00)
Then declare a string called
SecondTotalhours= Math.Floor(tshour2.TotalHours) + ":" + (tshour2.Minutes < 10 ? "0" + tshour2 .Minutes : tshour2 .Minutes.ToString());
Then to sum these first time value and the second time value:
string[] strTotalWorkedHours = FirstTotalHrs.Split(':');
string strFirstWorkingHours = strTotalWorkedHours[0];
string strFirstWorkingMinutes = strTotalWorkedHours[1];
string[] strLeaveHours = SecondTotalhours.Split(':');
string strFirstLeavehours = strLeaveHours[0];
string strFirstLeaveMinutes = strLeaveHours[1];
TimeSpan tsHours = new TimeSpan(0, 0, 0);
tsHours = TimeSpan.FromHours(Convert.ToInt32(strFirstWorkingHours) + Convert.ToInt32(strFirstLeavehours));
TimeSpan tsMinutes = new TimeSpan(0, 0, 0);
tsMinutes = TimeSpan.FromMinutes(Convert.ToInt32(strFirstWorkingMinutes) + Convert.ToInt32(strFirstLeaveMinutes));
string strTotalHours = Math.Floor(tsHours.TotalHours + tsMinutes.TotalHours) + ":" + (tsMinutes.Minutes < 10 ? "0" + tsMinutes.Minutes : tsMinutes.Minutes.ToString() + ":" + (tsHours.Seconds < 10 ? "0" + tsHours.Seconds : tsHours.Seconds.ToString()));
This will give you the sum of HH:MM:SS.
Thanks && Regards,
V. Santhi
Thanks & Regards,
Santhi .V
saisuresh074-17816, if this helps please login to Mark As Answer. | Alert Moderator