Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple time compare

Status
Not open for further replies.

ironhide1975

Programmer
Feb 25, 2003
451
US
I'm sure this is really simple but I'm having a hard time finding an example. I want to do a time compare before an ASP page starts a calculation and when it ends. I am somewhat close with this but I can't get the write formatting of this with seconds and minutes. Can someone help me clarify this forumla?

Code:
<%
todaysDate=now()
StartTime = FormatDateTime(todaysDate,3)

'lots of stuff happen here

todaysDate=now()
EndTime = FormatDateTime(todaysDate,3)

DiffTime = DateDiff("s",StartTime,EndTime)
DiffTime = FormatDateTime(DiffTime,3)
      
h1 = (DateDiff("h",StartTime,EndTime))
n1 = (DateDiff("n",StartTime,EndTime))
s1 = (DateDiff("s",StartTime,EndTime))

%>
Time Difference <%=h1 %>:<%=n1 %>:<%=s1 %> <br />


 
How about leaving both "Before" and "After" as dates rather than converting them to strings. Then you won't have the implicit conversion back to dates by the DateDiff funciton.

Code:
<%
StartTime = now()

'lots of stuff happen here

EndTime = now()
      
h1 = (DateDiff("h",StartTime,EndTime))
n1 = (DateDiff("n",StartTime,EndTime))
s1 = (DateDiff("s",StartTime,EndTime))
%>
Time Difference <%=h1 %>:<%=n1 %>:<%=s1 %> <br />
 
Or maybe something like this:
Code:
<%
StartTime = now()

'lots of stuff happen here

EndTime = now()

MathTime = cDate(cDbl(StartTime ) - cDbl(EndTime ))
h1 = Hour(MathTime)
n1 = Minute(MathTime)
s1 = Second(MathTime)
%>
Time Difference <%=h1 %>:<%=n1 %>:<%=s1 %> <br />


 
Did you want something like this:
store the Timer value at the start and at the end then compare the two.. will give you a rough idea of the time taken for the page to load... but it's level of accuracy is pretty rubbish - 10th of a second or something like that, so it depends on how fast your page loads as to how useful the result will be.

If you want better accuracy, then use a jscript function at the start and end of the page and use the getMillisecond method of Date() to return a more accurate number. You should be able to reference the JScript variables in your normal VBScript too.

Hope that helps

A smile is worth a thousand kind words. So smile, it's easy! :)
 
okay I get error

Code:
Microsoft VBScript runtime error '800a000d' 

Type mismatch: 'cDbl'

 
Try just pasting the following into a new ASP and then request it from your web server:
Code:
<%
StartTime = now()

'lots of stuff happen here
y = 0
for x = 1 to 15000000
  y = y + 1
next

EndTime = now()

MathTime = cDate(cDbl(StartTime ) - cDbl(EndTime ))
h1 = Hour(MathTime)
n1 = Minute(MathTime)
s1 = Second(MathTime)
%>
Time Difference <%=h1 %>:<%=n1 %>:<%=s1 %> <br />

This should display how many seconds it takes to count to fifteen million. Probably 10 or less.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top