Hi nauna,
I have created sample code which fulfill your requirement.
HTML
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Label ID="lblTime" Text="text" runat="server" />
<asp:Timer ID="timer" runat="server" Interval="1000">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("EndDate", typeof(DateTime));
dt.Rows.Add("2017-03-08 17:00:34.943");
DateTime startDate = DateTime.Now;
DateTime endDate = Convert.ToDateTime(dt.Rows[0]["EndDate"].ToString());
lblTime.Text = CalculateTimeDifference(startDate, endDate);
}
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
Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim dt As New DataTable()
dt.Columns.Add("EndDate", GetType(DateTime))
dt.Rows.Add("2017-03-08 17:00:34.943")
Dim startDate As DateTime = DateTime.Now
Dim endDate As DateTime = Convert.ToDateTime(dt.Rows(0)("EndDate").ToString())
lblTime.Text = CalculateTimeDifference(startDate, endDate)
End Sub
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
Screenshot