Velocity Reviews > Calculating number of seconds given two times

# Calculating number of seconds given two times

Guest
Posts: n/a

 04-27-2004
Hello,

I need to know how I can calculate the number of seconds between two
time stamps, e.g. if I have the following (using ToLongTimeString)

8:28:21 PM

and

9:02:33 PM

How can I find out the number of seconds elapsed between the two
times?

Ken Cox [Microsoft MVP]
Guest
Posts: n/a

 04-27-2004

Look at the TimeSpan example:

(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
If Not IsPostBack Then
viewstate("starttime") = Now
Else
Dim tmspan As TimeSpan
tmspan = Date.Now.Subtract _
(CType(viewstate("starttime"), DateTime))
Label1.Text = tmspan.TotalSeconds.ToString
End If
End Sub

"Asad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hello,
>
> I need to know how I can calculate the number of seconds between two
> time stamps, e.g. if I have the following (using ToLongTimeString)
>
> 8:28:21 PM
>
> and
>
> 9:02:33 PM
>
> How can I find out the number of seconds elapsed between the two
> times?
>
>

Matt Berther
Guest
Posts: n/a

 04-27-2004
Hello http://www.velocityreviews.com/forums/(E-Mail Removed),

I'll presume that you have both times as DateTime objects. If not, you'll need to parse them and then call the Subtract method to get a TimeSpan object.

TimeSpan span = dt.Subtract(dt2);
int seconds = span.Seconds;

> Hello,
>
> I need to know how I can calculate the number of seconds between two
> time stamps, e.g. if I have the following (using ToLongTimeString)
>
> 8:28:21 PM
>
> and
>
> 9:02:33 PM
>
> How can I find out the number of seconds elapsed between the two
> times?
>
>
>

--

--
Matt Berther
http://www.mattberther.com