Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Time to run a program


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: Time to run a program
Date   Wed, 12 May 2004 12:40:17 -0400

At 06:06 PM 5/12/2004 +0200, Jean-Benoit Hardouin wrote:
this command permet to display the date/time, but don't solve my problem (Perhaps I have not see all the subtleties of this command).

My problem is to compute the time between the beginning and the end of the running of a program.

Thank you for your help.
[...]

As you mentioned in your earlier message, you can take the time using $S_TIME (or, equivalently, c(current_time) ).

I'm usually content to just display them and mentally take the difference. But it is possible to automate this. You would need to textually take apart the time value into its components, and convert to numbers. Thus:
local time1 = c(current_time)
scalar hour1 = real(substr("`time1'", 1, 2))
scalar min1 = real(substr("`time1'", 4, 2))
scalar sec1 = real(substr("`time1'", 7, 2))

Do the same for another moment in time.

Then you need to subtract them. The easiest way would be to convert them into seconds (within the day): hour1 * 3600 + min1 * 60 + sec1.

Of course, there are complications if the run spans different days. I leave that to you.

Good luck.
-- David

David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index