Jump to content
Macro Express Forums

How do I check number of seconds elapsed?


Recommended Posts

I am monitoring several processes which can run for more than 24 hours, although typically less. Is there a fairly straightforward way to check how long certain process has been running, which won't get confused by change in time/date over midnight/new year. I only need 1 second resolution.

 

I know I could solve this by copying the Date/Time and doing a whole bunch of string/integer manipulation to eventually get the answer but hoping that either:

- there is an easier method

- someone has already solved this and can share some code

 

Note that I don't want to wait for anything - as in stop program execution while waiting for a time, but monitor elapsed time and act upon that after certain elapsed time points.

 

So in summary: Looking for Elapsed time monitor in seconds, perhaps returning something similar to a "Unix" time number.

Link to comment
Share on other sites

I understand the concern about going past midnight. 86,400 all of a sudden is back to zero. However, are you simply looking for a command line to save the seconds past midnight to a variable when the macro hits that line?

Link to comment
Share on other sites

Thanks for the ideas guys.

@joe I am not sure what you mean, perhaps I can try make myself a little bit clearer with a more concrete example. Let's say I start the monitoring at 22:00. Let's also say that in general I want to start a new action whenever the existing macro has been running for 10,000 seconds.

 

A straightforward query of the Date/Time string would not work, because as you say the number of seconds gets reset, so I need extra logic that won't be confused by a midnight change, preferably not relying on outside scripts, but of course will look at that if it is the only viable solution.

Link to comment
Share on other sites

In my book, unattended operations was always the most fun. Always had structural solutions. And was usually very reliable. But it all depends on how the gears are designed to work.

 

One thought is that you know what time it will be 10,000 seconds into the future. If the time is exactly 10pm (2200) on Friday the 4th when you fire up the macro then the target time would be Saturday the 5th at 00:46:40 am. One solution would then be to have the macro check the current date and time in each loop to see if it's past its bedtime, yet.

Link to comment
Share on other sites

Out of curiosity I decided to see how quickly I could write a macro to calculate elapsed time. Here is my sample macro:

// Get Starting time
Date/Time: Set %StartTime% to the current date/time
 
Variable Set Integer %RandomDelayTime% to a random value between 0 and 15
Delay: %RandomDelayTime% seconds
 
// Get Ending time
Date/Time: Set %EndTime% to the current date/time
 
// Calculate elapsed time
Variable Modify Date/Time: %ElapsedTime% = %StartTime% - %EndTime% 
Variable Modify Date/Time: %decElapsedTime% = %EndTime% - %StartTime% 
Variable Modify Decimal: %ElapsedSeconds% = %decElapsedTime% * 100000
 
// Display result
Text Box Display: Result
You can copy and paste this into your macro:

<COMMENT Value="Get Starting time"/>
<DATE/TIME Flags="\xB0" Date="7/3/2014 8:21:49 AM" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%StartTime%" IsDateVar="TRUE"/>
<COMMENT/>
<VARIABLE SET INTEGER Option="\x05" Destination="%RandomDelayTime%" Minimum="0" Maximum="15"/>
<DELAY Flags="\x01" Time="%RandomDelayTime%"/>
<COMMENT/>
<COMMENT Value="Get Ending time"/>
<DATE/TIME Flags="\xB0" Date="7/3/2014 8:21:49 AM" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%EndTime%" IsDateVar="TRUE"/>
<COMMENT/>
<COMMENT Value="Calculate elapsed time"/>
<VARIABLE MODIFY DATE/TIME DateVar="%ElapsedTime%" Option="\x01" LeftVar="%StartTime%" RightVal="%EndTime%" UseInteger="TRUE" MathOpt="\x00"/>
<VARIABLE MODIFY DATE/TIME DateVar="%decElapsedTime%" Option="\x01" LeftVar="%EndTime%" RightVal="%StartTime%" UseInteger="TRUE" MathOpt="\x00"/>
<VARIABLE MODIFY DECIMAL Option="\x02" Destination="%ElapsedSeconds%" Value1="%decElapsedTime%" Value2="100000"/>
<COMMENT/>
<COMMENT Value="Display result"/>
<TEXT BOX DISPLAY Title="Result" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 decElapsedTime: %decElapsedTime%\r\n\\par ElapsedSeconds:  %ElapsedSeconds%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="462" Height="133" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
This may be the same or similar as the sample previously referenced. I did not open that sample to compare.
  • Like 1
Link to comment
Share on other sites

@Samrae, just a small error:

// Calculate elapsed time
Variable Modify Date/Time: %ElapsedTime% = %StartTime% - %EndTime%
Variable Modify Date/Time: %decElapsedTime% = %EndTime% - %StartTime%
Variable Modify Decimal: %ElapsedSeconds% = %decElapsedTime% * 100000

 

That constant should be 86400 (the number of seconds in a day) and not 100,000.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...