Time Calculation

Discussion in 'ASP General' started by Rob, May 17, 2005.

  1. Rob

    Rob Guest

    I would like to display the difference between the logging time
    [Session("start"] and the current time [now]. In hours minutes and seconds,
    I have tried a couple of things but all I see is gobbledy gook.

    Any guidance would be appreciated.

    Regards,

    Rob
     
    Rob, May 17, 2005
    #1
    1. Advertising

  2. Rob wrote:
    > I would like to display the difference between the logging time
    > [Session("start"] and the current time [now]. In hours minutes and
    > seconds, I have tried a couple of things but all I see is gobbledy
    > gook.
    >
    > Any guidance would be appreciated.
    >


    Assuming, in global.asa, you have:
    Sub Session_onstart()
    Session("start") = Now
    End Sub

    In your asp page, you would calculate the difference in seconds:

    dim timelogged
    timelogged = datediff("s",cdate(Session("start")), Now)

    Then calculate the hours, min. etc from that:

    dim hourslogged
    hourslogged=timelogged\3600

    I'll leave the rest as "an exercise for the student".
    Let us know if you need help with the rest. I think there is an article
    about doing this at aspfaq, but I'm not sure.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], May 17, 2005
    #2
    1. Advertising

  3. Rob

    dlbjr Guest

    Function GetAgeStamp(dtmStartDate)
    If IsDate(dtmStartDate) Then
    intDays = 0
    intHours = 0
    intMinutes = 0
    dblTotalSeconds = DateDiff("s",dtmStartDate,Now())
    If dblTotalSeconds >= 86400 Then intDays = dblTotalSeconds \ 86400
    If intDays > 0 Then dblTotalSeconds = dblTotalSeconds Mod 86400
    If dblTotalSeconds >= 3600 Then intHours = dblTotalSeconds \ 3600
    If intHours > 0 Then dblTotalSeconds = dblTotalSeconds Mod 3600
    If dblTotalSeconds >= 60 Then intMinutes = dblTotalSeconds \ 60
    If intMinutes > 0 Then dblTotalSeconds = dblTotalSeconds Mod 60
    Dim ar(3)
    ar(0) = Right("0" & intDays,2)
    ar(1) = Right("0" & intHours,2)
    ar(2) = Right("0" & intMinutes,2)
    ar(3) = Right("0" & dblTotalSeconds,2)
    GetAgeStamp = Join(ar,":")
    End If
    End Function

    --
    'dlbjr
    'Pleading sagacious indoctrination!
     
    dlbjr, May 17, 2005
    #3
  4. dlbjr wrote:
    > Function GetAgeStamp(dtmStartDate)
    > If IsDate(dtmStartDate) Then
    > intDays = 0
    > intHours = 0
    > intMinutes = 0
    > dblTotalSeconds = DateDiff("s",dtmStartDate,Now())
    > If dblTotalSeconds >= 86400 Then intDays = dblTotalSeconds \ 86400
    > If intDays > 0 Then dblTotalSeconds = dblTotalSeconds Mod 86400
    > If dblTotalSeconds >= 3600 Then intHours = dblTotalSeconds \ 3600
    > If intHours > 0 Then dblTotalSeconds = dblTotalSeconds Mod 3600
    > If dblTotalSeconds >= 60 Then intMinutes = dblTotalSeconds \ 60
    > If intMinutes > 0 Then dblTotalSeconds = dblTotalSeconds Mod 60
    > Dim ar(3)
    > ar(0) = Right("0" & intDays,2)
    > ar(1) = Right("0" & intHours,2)
    > ar(2) = Right("0" & intMinutes,2)
    > ar(3) = Right("0" & dblTotalSeconds,2)
    > GetAgeStamp = Join(ar,":")
    > End If
    > End Function
    >


    Awwww - you spoiled Rob's exercise. Now he'll never discover whether or not
    he could have written this himself ...
    ;-)

    Why did you reply to me? I've already got a similar function in my library
    ....

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], May 17, 2005
    #4
  5. Rob

    dlbjr Guest

    Drinkin' to heavy I guess. Should take on a light beer!

    Sorry Bob

    --
    'dlbjr
    'Pleading sagacious indoctrination!
     
    dlbjr, May 18, 2005
    #5
    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. falcon
    Replies:
    10
    Views:
    583
    falcon
    Mar 13, 2006
  2. mazdotnet

    Daylight saving time calculation

    mazdotnet, Oct 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    338
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
    Oct 15, 2006
  3. flamesrock
    Replies:
    8
    Views:
    548
    Hendrik van Rooyen
    Nov 24, 2006
  4. SSG

    Running time calculation

    SSG, Jul 7, 2005, in forum: C Programming
    Replies:
    3
    Views:
    481
    Anonymous 7843
    Jul 7, 2005
  5. calculation of cpu idle time

    , Aug 23, 2006, in forum: C Programming
    Replies:
    33
    Views:
    1,027
    jmcgill
    Aug 29, 2006
Loading...

Share This Page