working out time passed between two dates

S

Steven Scaife

I am trying to work out the length of time that a page was opened till it
reached another page, I amusing the script below

End_Of_Call = formatdatetime(now(), 0)

'work out the duration of the call
duration = End_Of_Call - cdate(vTime)
response.write isdate(End_Of_Call)
response.write isdate(vTime)
'response.write duration
response.End()

but it errors and i get

Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "7/21/2004 2:34:49 PM"]'
/testing/process_new.asp, line 30

I cant understand why it doesn't work, it is being run on the same server as
before and is identical code, except i dont use formatdatetime on both
variables to set them, if i remove formatdatetime i still get type mismatch,
any ideas how i can make this work. thanks
 
S

Steven Scaife

all i get when i dont get that error is something like so
3.00925930787344E-04

when i use duration = now() + 10 - now() - get 10

cant understand why it doesn't do it, really annoying as this way used to
work
 
R

Ray at

Use the DateDiff function:

<quote>
Returns the number of intervals between two dates.

DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
</quote>




'work out the duration of the call

duration = DateDiff("s", Now, vTime)
response.write duration
response.End

That will tell you how many seconds have passed. For more info on the
DateDiff function, see your WSH documentation that you downloaded and
installed from
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9

Ray at work
 
A

Aaron [SQL Server MVP]

Why are you using subtraction? Do you even know what the default unit is
for date/time-based math? Why don't you use datediff instead of confusing
things with this shorthand?
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top