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

Re: st: Extracting a string from c(current_time)


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: Extracting a string from c(current_time)
Date   Fri, 25 Mar 2005 14:38:10 +0900

John-Paul Ferguson wrote (excerpted):

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?

----------------------------------------------------------------------------

Something like the following should work.

Joseph Coveney


program autolog
     local now = subinstr("`c(current_time)'", ":", "", .)
     local today = string(date("`c(current_date)'", "dmy"), "%dCYND")
     local timestamp `today'T`now'
// capture log close
     log using `timestamp'.log, replace
end


. autolog
(note: file A:\20050325T143342.log not found)
----------------------------------------------------------------------------
----------------------
       log:  A:\20050325T143342.log
  log type:  text
 opened on:  25 Mar 2005, 14:33:43

. log close
       log:  A:\20050325T143342.log
  log type:  text
 closed on:  25 Mar 2005, 14:33:46
----------------------------------------------------------------------------
----------------------






*
*   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