Geeks With Blogs

News

Free counters
Added on January 19,2012

Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.

Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

Here's an example (One Way) on how are we going to calculate the time difference between two give time:

C#

`        DateTime dFrom;        DateTime dTo;        string sDateFrom = "11:56:00";        string sDateTo = "12:12:00";        if (DateTime.TryParse(sDateFrom, out dFrom) && DateTime.TryParse(sDateTo, out dTo))        {            TimeSpan TS = dTo - dFrom;            int hour = TS.Hours;            int mins = TS.Minutes;            int secs = TS.Seconds;            string timeDiff = hour.ToString("00") + ":" + mins.ToString("00") + ":" + secs.ToString("00");            Response.Write(timeDiff); //output 16 mins in format 00:16:00        } `

VB.NET

`Dim dFrom As DateTimeDim dTo As DateTimeDim sDateFrom As String = "11:56:00"Dim sDateTo As String = "12:12:00"If DateTime.TryParse(sDateFrom, dFrom) AndAlso DateTime.TryParse(sDateTo, dTo) Then    Dim TS As TimeSpan = dTo - dFrom    Dim hour As Integer = TS.Hours    Dim mins As Integer = TS.Minutes    Dim secs As Integer = TS.Seconds    Dim timeDiff As String = ((hour.ToString("00") & ":") + mins.ToString("00") & ":") + secs.ToString("00")    Response.Write(timeDiff)'output 16 mins in format 00:16:00End If`

Technorati Tags:
Posted on Tuesday, February 17, 2009 3:08 PM ASP.NET | Back to top

Related Posts on Geeks With Blogs Matching Categories

Comments on this post: Get the Difference Between Two Time in ASP.NET

# re: Get the Difference Between Two Time in ASP.NET
Not Working when we are calculating the Difference between PM TO AM
Ex:-string sdatefrom = 23:40
string stofrom = 02:20
Left by Basha on Jun 26, 2011 7:37 PM