Hi nauna,
Use PadLeft method.
Check with below modified code.
C#
public void timecal(string startdate, string enddate)
{
TimeSpan ts = DateTime.Parse(enddate) - DateTime.Parse(startdate);
string lbl = "";
if (ts.Days > 0)
{
lbl = string.Format("{0}:{1}", ts.Days * 24 + ts.Hours, ts.Minutes.ToString().PadLeft(2, '0'));
}
else
{
lbl = string.Format("{0}:{1}", ts.Hours, ts.Minutes.ToString().PadLeft(2, '0'));
}
result = lbl;
}
VB.Net
Public Sub timecal(ByVal startdate As String, ByVal enddate As String)
Dim ts As TimeSpan = DateTime.Parse(enddate) - DateTime.Parse(startdate)
Dim lbl As String = ""
If ts.Days > 0 Then
lbl = String.Format("{0}:{1}", ts.Days * 24 + ts.Hours, ts.Minutes.ToString().PadLeft(2, "0"c))
Else
lbl = String.Format("{0}:{1}", ts.Hours, ts.Minutes.ToString().PadLeft(2, "0"c))
End If
result = lbl
End Sub