[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Time to run a program
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
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.
Institute for Policy Studies
Johns Hopkins University
* For searches and help try: