PeterlFF Posted March 2, 2022 Share Posted March 2, 2022 I have been searching Help and the forums but can't find exactly what I am looking for. I'm using AutoIT to execute a task and I want to capture the start time of the task, the end time, and the amount of time it took (down to a hundredth of a second). I want the results in the mm:ss:ms format. I tried using TimerInit and TimerDiff which gives me the amount of time in milliseconds the task took, and I found a way to convert it to the format I want but it is a bit bulky. $time1 = TimerInit() Run ("Notepad.exe") sleep(1200) WinWaitActive("Untitled - Notepad") $timet = TimerDiff($time1) $time2 = $time1 + $timet $hour = Floor($time1 / 3600000) $remanH = Mod($time1, 3600000) $min = Floor($remanH / 60000) $remanM = Mod($remanH, 60000) $sec = Floor($remanM / 1000) $remanS = Mod($remanM, 1000) $msec = Floor($remanS) $Task1a = $min & ":" & $sec & ":" & $msec $hour = Floor($time2 / 3600000) $remanH = Mod($time2, 3600000) $min = Floor($remanH / 60000) $remanM = Mod($remanH, 60000) $sec = Floor($remanM / 1000) $remanS = Mod($remanM, 1000) $msec = Floor($remanS) $Task1b = $min & ":" & $sec & ":" & $msec $hour = Floor($timet / 3600000) $remanH = Mod($timet, 3600000) $min = Floor($remanH / 60000) $remanM = Mod($remanH, 60000) $sec = Floor($remanM / 1000) $remanS = Mod($remanM, 1000) $msec = Floor($remanS) $Task1c = $min & ":" & $sec & ":" & $msec I also tried capturing the start and end times using code below when the task begins and ends but haven't figured out how to do a calculation between the start and end times to get the actual time the task took: $task1a = (@Hour & ':' & @Min & ':' & @Sec & ':' & @MSec) Either way I would like to drop the thousandth millisecond and just have the 2 digits but not sure how to do that. Can anyone offer a suggestion on a better to collect my times? Link to comment Share on other sites More sharing options...
Nine Posted March 2, 2022 Share Posted March 2, 2022 Do not use the result of timerinit as a value. Consider it as a handle to the timer you started. TimerDiff will give you a right value of an elapse time. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
PeterlFF Posted March 2, 2022 Author Share Posted March 2, 2022 OK. I was using it as my start time since I want start time, end time, and the difference between the two. What would you suggest I use instead? Link to comment Share on other sites More sharing options...
Nine Posted March 2, 2022 Share Posted March 2, 2022 See help file for both functions, there is examples how to use them properly. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
PeterlFF Posted March 3, 2022 Author Share Posted March 3, 2022 Thanks but those don't do what I want (as far as I can tell). The examples just produce the time difference which is only part of what I want. Link to comment Share on other sites More sharing options...
Nine Posted March 3, 2022 Share Posted March 3, 2022 Make an effort in trying to produce a basic script. Then we will try to help you “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
PeterlFF Posted March 3, 2022 Author Share Posted March 3, 2022 I already included the pertinent parts of my efforts in my original post that I have tried as I test this out. I will include all of what I have tried so far but there isn't much more than I already shared. One attempt: $task1a = (@Hour & ':' & @Min & ':' & @Sec & ':' & @MSec) Run ("Notepad.exe") WinWaitActive("Untitled - Notepad") sleep(1000) $task1b = (@Hour & ':' & @Min & ':' & @Sec & ':' & @MSec) $task1c = $task1a - $task1b MsgBox(0, "Time start", "Start " & $task1a & " Stop " & $task1b & " time " & $task1c) WinClose("Untitled - Notepad") and then this: $time1 = TimerInit() ; Begin the timer and store the handle in a variable. Run ("Notepad.exe") sleep(1200) WinWaitActive("Untitled - Notepad") $timet = TimerDiff($time1) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff. $time2 = $time1 + $timet $hour = Floor($time1 / 3600000) $remanH = Mod($time1, 3600000) $min = Floor($remanH / 60000) $remanM = Mod($remanH, 60000) $sec = Floor($remanM / 1000) $remanS = Mod($remanM, 1000) $msec = Floor($remanS) $Task1a = $min & ":" & $sec & ":" & $msec $hour = Floor($time2 / 3600000) $remanH = Mod($time2, 3600000) $min = Floor($remanH / 60000) $remanM = Mod($remanH, 60000) $sec = Floor($remanM / 1000) $remanS = Mod($remanM, 1000) $msec = Floor($remanS) $Task1b = $min & ":" & $sec & ":" & $msec $hour = Floor($timet / 3600000) $remanH = Mod($timet, 3600000) $min = Floor($remanH / 60000) $remanM = Mod($remanH, 60000) $sec = Floor($remanM / 1000) $remanS = Mod($remanM, 1000) $msec = Floor($remanS) $Task1c = $min & ":" & $sec & ":" & $msec MsgBox($MB_SYSTEMMODAL, "Time Difference", "start " & $Task1a & " end " & $Task1b & " diff " & $Task1c) WinClose("Untitled - Notepad") Link to comment Share on other sites More sharing options...
Nine Posted March 3, 2022 Share Posted March 3, 2022 here : Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. ;do something here ; Local $iTime = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. Local $iTime = 4657891 ; for testing purpose here ConsoleWrite("Time in ms " & $iTime & @CRLF) $iTime = Int($iTime/1000) ; make it in secs Local $hour = Floor($iTime / 3600) ConsoleWrite("Number of hours = " & $hour & @CRLF) $iTime -= $hour * 3600 Local $min = Floor($iTime / 60) ConsoleWrite("Number of mins = " & $min & @CRLF) Local $sec = Mod($iTime, 60) ConsoleWrite("Number of secs = " & $sec & @CRLF) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
Developers Jos Posted March 3, 2022 Developers Share Posted March 3, 2022 Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
PeterlFF Posted March 3, 2022 Author Share Posted March 3, 2022 Nine, thanks for the response. Your code gives me the length of time my task takes but I also want to capture the start and end times. You said using the value of TimerInit as my start time isn't a good idea but I'm not sure how else to get it. Does the below look like a bad idea? Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. ConsoleWrite("Start Time in ms " & $hTimer & @CRLF) ; Start time sleep(900) Local $iTime = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. $eTime = $hTimer + $iTime ; Add TimerInit TimerDiff results to generate End time. ;Local $iTime = 4657891 ; for testing purpose here ConsoleWrite("Time in ms " & $iTime & @CRLF) ConsoleWrite("End Time in ms " & $eTime & @CRLF) Link to comment Share on other sites More sharing options...
Nine Posted March 3, 2022 Share Posted March 3, 2022 31 minutes ago, PeterlFF said: but I also want to capture the start and end times In what terms ? hour:min:sec:msec ? If it is in ms what would the anchor ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
PeterlFF Posted March 3, 2022 Author Share Posted March 3, 2022 Ultimately in min:sec:msec (00:00:0) but I only need the tenths of seconds (the first digit of msec). If I can only capture it in milliseconds then I can convert it to min:sec:msec. Link to comment Share on other sites More sharing options...
Nine Posted March 3, 2022 Share Posted March 3, 2022 Local $sStart = @MIN & ":" & @SEC & ":" & Int(Number(@MSEC)/100) ConsoleWrite($sStart & @CRLF) Notice that all the date and time macros return a string. If you require to use them in arithmetical expression, it is recommended to convert them in number beforehand. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
PeterlFF Posted March 3, 2022 Author Share Posted March 3, 2022 Thank you for your time and patience. I think that gives me all I need to forge ahead. 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