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

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Frank Buss VHDL 3 07-31-2006 06:48 PM Michael Tan Ruby 32 07-21-2005 03:23 PM Kishor C Programming 13 02-03-2004 11:30 PM cyril C Programming 4 08-25-2003 08:25 AM Tim ASP General 3 08-05-2003 07:45 PM