Jump to content

Recommended Posts

Posted (edited)

Hi

Is it possible to capture a "Start time" and an "End time" in AutoIT and then do a DateDiff between the 2 that will display the difference between the 2 times in seconds only?

Any help would be appreciated.

Thanks

Edited by Kasteel
Posted (edited)

Opt("OnExitFunc", "ScriptExit")

$Timer = TimerInit()

While 1
    
    For $i = 1 to 5
        ConsoleWrite($i & @CR)
        Sleep(1000)
        
        If $i = 5 Then
            Exit
        EndIf
    Next
    
WEnd


Func ScriptExit()
    $TimerTime = TimerDiff($Timer)
    $TimerTimeSecs = ($TimerTime / 1000)
    ConsoleWrite("Exit Time after " & $TimerTimeSecs & " seconds." & @CR)
EndFunc

Returns for me..

1
2
3
4
5
Exit Time after 5.00215248 seconds.
>Exit code: 0    Time: 5.213

Edit: monoceres beat me to it, but my method used the OnExitFunc option for capturing whenever your programs exit.

Edited by Demonic
Posted

Hi

Thanks for the quick reply. It does not have to be DateDiff.

The code you showed me is very cool.

Can you please explain how it works? Still new to AutoIT.

Thanks

:D

Is it necessary to do it with DateDiff?

Else it's easy as pie.

$timer=TimerInit()
Sleep(Random(1000,2000,1))
MsgBox(0,"That took:",Round(TimerDiff($timer)/1000,1)&" seconds.")

Posted

Sure,

TimerInit() creates a time stamp (how it looks is irrelevant).

Sleep just, sleeps, how long is decided by the parameter (in milliseconds), in this case I make it random (between 1000 and 2000 ms).

TimerDiff returns how many milliseconds has passed since the time stamp was created, it's then divided by 1000 and rounded to 1 decimal.

Broken link? PM me and I'll send you the file!

Posted

Awesome!!

Thanks for the replies. :D

Sure,

TimerInit() creates a time stamp (how it looks is irrelevant).

Sleep just, sleeps, how long is decided by the parameter (in milliseconds), in this case I make it random (between 1000 and 2000 ms).

TimerDiff returns how many milliseconds has passed since the time stamp was created, it's then divided by 1000 and rounded to 1 decimal.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...