Velocity Reviews > Time Calculation

# Time Calculation

Rob
Guest
Posts: n/a

 05-17-2005
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

Bob Barrows [MVP]
Guest
Posts: n/a

 05-17-2005
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.

dlbjr
Guest
Posts: n/a

 05-17-2005
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

Bob Barrows [MVP]
Guest
Posts: n/a

 05-17-2005
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.

dlbjr
Guest
Posts: n/a

 05-17-2005
Drinkin' to heavy I guess. Should take on a light beer!

Sorry Bob

--
'dlbjr