Time Calculation

R

Rob

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
 
B

Bob Barrows [MVP]

Rob said:
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
 
D

dlbjr

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
 
B

Bob Barrows [MVP]

dlbjr said:
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
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top