[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Extracting a string from c(current_time)
I am trying to write a program (here called -autolog-), for use in a do-file,
that creates a unique, time-stamped log whenever the program is run. For
example, running the do-file that contains autolog at 11:45.22 on the 24th of
March would produce 24Mar2005_114522.log, or something similar. My first
attempt is below:
local time c(current_time)
local logtime: subinstr local time ":" "", all
local date c(current_date)
local logdate: subinstr local date " " "", all
local timestamp `logdate'_`logtime'
log using `timestamp'.log, replace
The idea is straightforward. Since I work part-time in Windows, which will not
accept colons in file names, I wanted to strip the colons out of the current
time (and, less critically, the spaces out of the current date).
However, Stata seems to parse the current_time value as a single token no matter
what, and thus doesn't "see" the colons within it. (A smart idea, under other
circumstances!) It similarly ignores the spaces in current_date.
My question therefore is this: how can I retrieve the current date or time and
hold it as a genuine string, such that I can manipulate it? The answer is
probably basic, but I haven't been able to find anything obvious in the user's
guide or online (I don't have _Programming Stata_, alas).
Thanks for your help,
Institute for Work and Employment Research
Sloan School of Management
Massachusetts Institute of Technology
* For searches and help try: