Calculating number of seconds given two times

A

Asad

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
 
K

Ken Cox [Microsoft MVP]

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
 
M

Matt Berther

Hello (e-mail address 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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top