Micro Focus QTP (UFT) Forums

Full Version: time difference
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i had started my execution at Start_time = time
and it ended at End_time = time

now i want the differnec in hrs and mins that how much time it has taken to execute
like TotalTime =End_time -Start_time

can anybody send me the code for same
You can build a custom function using the built-in functions :- Hour, minute, Second.
you can use 'Timer' in your script.
e.g
Code:
StartTime = Timer
...
Your Test statements
...
EndTime = Timer
msgbox  EndTime-StartTime
The only problem with Timer is if you run overnight, it won't work right. because the timer is the seconds in the day and starts back at 0 at the beginning of the day.
It worked For me ; pls find the Code below :[/u]

Code:
Function Total_Execution_Time(Start_Time,End_Time)

    total number of seconds
    TotalTime_Secs  = Datediff("s",Start_Time,End_Time)

    'convert  total  Seconds into "Seconds only/ Mins+Secs/ Hrs+Mins+Secs"
    If TotalTime_Secs < 60 Then
        TotalTime = "Total Time Taken For Complete Execution = " & TotalTime_Secs  & " Second(s) Approx."
    ElseIf    TotalTime_Secs >=60 and TotalTime_Secs < 3600 Then
        TotalTime = "Total Time Taken For Complete Execution = " & int(TotalTime_Secs/60) & " Minute(s) and "& TotalTime_Secs Mod 60 & " Second(s) Approx."
    ElseIf    TotalTime_Secs >= 3600 Then
        TotalTime = "Total Time Taken For Complete Execution = " & int(TotalTime_Secs/3600) & " Hour(s) , " & int((TotalTime_Secs Mod 3600)/60)  & " Minute(s) and "& ((TotalTime_Secs Mod 3600 ) Mod 60) & " Second(s)  Approx."
    End If

    'Return the Message
    Total_Execution_Time = TotalTime
End Function
Thats great learner1,

always put the formatted code here, use proper tags while posting.
This helps your posts making more readable.
Sure Saket
Next will take care!!