1. ## Elapsed time

I have the code:

StartTime = Time()
...
EndTime = Time()

ElapsedTime = FormatDateTime(EndTime - StartTime, vbShortTime)

Which returns 01:03 for 1 hour and 3 minutes. But my test really runs 1 hour 3 minutex and 47 seconds.

How can I always add 1 extra minute for rounding up for the extra seconds?

2. ## Re: Elapsed time

Look at DateDiff function. And write your own logic for this

3. ## Re: Elapsed time

Try this

StartTime="05/07/2012 13:00:00"
EndTime= "05/07/2012 14:03:47"
ElapsedTime = DateDiff("s",StartTime,EndTime)

nTotalSeconds = ElapsedTime
If Round( nTotalSeconds / 60 ) = 60 Then
nhours = 1
Else
nHours = Int( nTotalSeconds / 3600 )
End If

nTotalSeconds = nTotalSeconds - (3600 * nHours)
If Round( nTotalSeconds / 60 ) = 60 Then
nminutes = 0
Else
nMinutes = Round( nTotalSeconds / 60 )
End If

msgBox "This test took "&amp;nHours&amp; " hour(s) and "&amp;nMinutes&amp; " minutes to complete"

4. ## Re: Elapsed time

Hi Greg,
Could you explain, for which input conditions you are using two if condition in your code.
Without the if conditions your code work properly.

StartTime="05/07/2012 13:00:00"
EndTime= "05/07/2012 14:00:00"
ElapsedTime = DateDiff("s",StartTime,EndTime)

nTotalSeconds = ElapsedTime

nHours = Int( nTotalSeconds / 3600 )

nTotalSeconds = nTotalSeconds - (3600 * nHours)

nMinutes = round( nTotalSeconds / 60 )

msgBox "This test took "&amp;nHours&amp; " hour(s) and "&amp;nMinutes&amp; " minutes to complete"

5. ## Re: Elapsed time

Without the if statements, you can get a result of 0 hours and 60 minutes.

StartTime="05/07/2012 13:00:01"
EndTime= "05/07/2012 14:00:00"

It needs to be enhanced to work perfectly.

6. ## Re: Elapsed time

Thx Greg and Mrinal,

I finished this last night with a little for functionality:

'Calulate elapsed Test run time
nTimeValue = DateDiff("s", StartTime, EndTime)
hrs = "00"

If nTimeValue &gt; 3600 Then
hrs = Fix(nTimeValue / 3600)
mins = Fix (Fix(nTimeValue - (hrs * 3600))/60)
secs = Cint(Fix(nTimeValue - (hrs * 3600)) - (mins * 60))
Else
mins = Fix(nTimeValue / 60)
secs = CInt(nTimeValue - (mins * 60))
End If
If hrs &lt; 10 and hrs &lt;&gt; 00 Then hrs = "0" &amp; hrs
If mins &lt; 10 Then mins = "0" &amp; mins
If secs &lt; 10 Then secs = "0" &amp; secs
ElapsedTime = hrs &amp; ":" &amp; mins &amp; ":" &amp; secs

thx for the ideas

7. ## Re: Elapsed time

Why not use Services.StartTransaction and Services.EndTransaction? My test ran for only seconds, and the result I got back was seconds with 4 decimal places. I'm not sure what it would give for minutes or hours.

8. ## Re: Elapsed time

Thanks GregEncke for the nice clarification. [img]/images/graemlins/ooo.gif[/img] [img]/images/graemlins/ooo.gif[/img]

9. ## Re: Elapsed time

Could you plz explain y not services.start transaction &amp; end transaction.i guess it also gives time for the test ran....Any limitation for that?

10. ## Re: Elapsed time

Kool_AJ,
You can use the default QTP feature services.start transaction &amp; end transaction or your customized code using VB Time function.

But services.start transaction &amp; end transaction feature can use in QTP script not in function file.
And in above case requirement is for determine the round off value.

Regards,
Mrinal

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.