How to show count down timer like Flipkart, Snapdeal, Amazon using C# and VB.Net in ASP.Net

Last Reply 7 days ago By Maheshspmc

Posted 7 days ago

how to display time difference in days,hrs,mins,secs from the difference of startdatetime and enddatetime from database records in a datalist..similar to online shopping timers..

Posted 7 days ago

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

 

I agree, here is the link: http://e-iceblue.com/free-api