Calculating number of seconds given two times

Discussion in 'ASP .Net' started by Asad, Apr 27, 2004.

  1. Asad

    Asad Guest

    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
    Asad, Apr 27, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    Ken Cox [Microsoft MVP], Apr 27, 2004
    #2
    1. Advertising

  3. Asad

    Matt Berther Guest

    Hello ,

    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
    Matt Berther, Apr 27, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    7
    Views:
    16,904
    tshad
    Mar 11, 2005
  2. cyril
    Replies:
    4
    Views:
    1,628
    cyril
    Aug 25, 2003
  3. Kishor
    Replies:
    13
    Views:
    1,450
    Sidney Cadot
    Feb 3, 2004
  4. Tim
    Replies:
    3
    Views:
    132
  5. Michael Tan
    Replies:
    32
    Views:
    929
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page