Calculate Total Hours and Minutes from string variable using C# and VB.Net in ASP.Net

Last Reply one year ago By pandeyism

Posted one year ago


i am using timespan to calculate time, it works fine but if timespan1 or timespan2 has value like 24:17  or 25:60 it gives erorr that it is out of range

please advice how can deal with it 


i can just replace if 24:17  so if hour is 24 and min is more than 00 so it replaces min with 00

string timeStamp1 = item.Time.Replace(" hours ", ":").Replace("min", "").Replace("hour", ":").Replace("min", "");
string timeStamp2 = lblholdingtime.Text.Replace(" hours ", ":").Replace("min", "").Replace("hour",":").Replace("min","");
ts1 = TimeSpan.Parse(timeStamp1);
ts2 = TimeSpan.Parse(timeStamp2);


int hours = 00;
int min = 00;
hours += ts1.Hours;
min +=ts1.Minutes;



This question does not have replies that have been liked.