Click to See Complete Forum and Search --> : Difficulty in comparing two strings of time


nyfiken
07-24-2005, 09:25 AM
Hi!

I have written some code that creates a session with the time when a visitor comes to my homepage and write a code in a text file for each pages that are requested together with the time.

What I have been doing all the day is to write some code that compare the start time with the end time(the last witten request)

I have cut the time strings into separate strings for minutes and seconds, but in the end I found out it didn't work. Look at this:

start time 12:58:20 PM and end time is 1:03:10 PM

If I compare the minutes 58 - 03 the result will be 55 minutes! The visitor has only been to the site for 5 minutes....!

Anyone that have some good advice how to solve this? Looking forward to get some replies!

Thanks nyfiken

buntine
07-24-2005, 05:05 PM
Your reinventing the wheel a bit here! VBScript has built-in date/time comparison functionality.

You can use the DateDiff function to get the differance in time.

' Get the number of minutes the user has been browsing your site:
Dim intMinutes, dteStartTime, dteEndTime

dteStartTime = CDate(YOUR_START_TIME)
dteEndTime = CDate(YOUR_END_TIME)
intMinutes = DateDiff("n", dteStartTime, dteEndTime)

Response.Write "You have been here for: " & intMinutes

See the following for more information on this function: http://www.w3schools.com/vbscript/func_datediff.asp

Regards.

nyfiken
07-24-2005, 05:45 PM
Thanks!

That was new for me! Very simple and useful code! Great!

But I thought that I could do the same with seconds, soo that I got the answer like "8 minutes and 15 seconds", but it didn't work the way I thought!!

response.write "You have been here for: " & time_min & "minutes" & " " & time_sec & "seconds"

When I used seconds "s" in DateDiff it return a very large number! Must be the total second!

Have I come to the end of the road? or is their some way to solve this or not? Would be interesting to know!

Regards
nyfiken