Kasteel Posted September 17, 2009 Share Posted September 17, 2009 (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 September 17, 2009 by Kasteel Link to comment Share on other sites More sharing options...
monoceres Posted September 17, 2009 Share Posted September 17, 2009 (edited) 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.") Edited September 17, 2009 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Demonic Posted September 17, 2009 Share Posted September 17, 2009 (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 September 17, 2009 by Demonic Link to comment Share on other sites More sharing options...
Kasteel Posted September 17, 2009 Author Share Posted September 17, 2009 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 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.") Link to comment Share on other sites More sharing options...
monoceres Posted September 17, 2009 Share Posted September 17, 2009 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! Link to comment Share on other sites More sharing options...
Kasteel Posted September 17, 2009 Author Share Posted September 17, 2009 Awesome!!Thanks for the replies. 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now