Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Calculating number of seconds given two times

Reply
Thread Tools

Calculating number of seconds given two times

 
 
Asad
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?

Thanks in advance.

Asad
 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      04-27-2004
Hi Asad,

Look at the TimeSpan example:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
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?
>
> Thanks in advance.
>
> Asad


 
Reply With Quote
 
 
 
 
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?
>
> Thanks in advance.
>
> Asad
>

--

--
Matt Berther
http://www.mattberther.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
standard function for calculating the number of bits of a natural number? Frank Buss VHDL 3 07-31-2006 06:48 PM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
Trouble calculating 5th root of a given number using C Kishor C Programming 13 02-03-2004 11:30 PM
A simple example calculating the number of seconds since 01/01/1970 cyril C Programming 4 08-25-2003 08:25 AM
Help! I am having problems with calculating the total seconds from two date/times. Tim ASP General 3 08-05-2003 07:45 PM



Advertisments