Hi Maheshspmc,
Use the below method.
C#
public string CalculateTimeDifference(DateTime startDate, DateTime endDate)
{
int days = 0; int hours = 0; int mins = 0; int secs = 0;
string final = string.Empty;
if (endDate > startDate)
{
days = (endDate - startDate).Days;
hours = (endDate - startDate).Hours;
mins = (endDate - startDate).Minutes;
secs = (endDate - startDate).Seconds;
final = string.Format("{0} days {1} hours {2} mins {3} secs", days, hours, mins, secs);
}
return final;
}
VB.Net
Public Function CalculateTimeDifference(startDate As DateTime, endDate As DateTime) As String
Dim days As Integer = 0
Dim hours As Integer = 0
Dim mins As Integer = 0
Dim secs As Integer = 0
Dim final As String = String.Empty
If endDate > startDate Then
days = (endDate - startDate).Days
hours = (endDate - startDate).Hours
mins = (endDate - startDate).Minutes
secs = (endDate - startDate).Seconds
final = String.Format("{0} days {1} hours {2} mins {3} secs", days, hours, mins, secs)
End If
Return final
End Function