Geeks With Blogs


Microsoft MVP


Moderator at CodeASP.NET

Quiz Master

free counters
Free counters
Added on January 19,2012

Follow Me @vmsdurano

A bit About Me

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:



        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




Dim dFrom As DateTime
Dim dTo As DateTime
Dim sDateFrom As String = "11:56:00"
Dim sDateTo As String = "12:12:00"
If DateTime.TryParse(sDateFrom, dFrom) AndAlso DateTime.TryParse(sDateTo, dTo) Then
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:00
End If


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

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

# re: Get the Difference Between Two Time in ASP.NET
Requesting Gravatar...
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

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: