>> Home >> Resources & support >> FAQs >> Current date and time

How can I put the current date and time in my log files?

Title   Current date and time
Author Jeremy B. Wernow, StataCorp
David Kantor, Johns Hopkins University

You can put the current date and time into your log files by displaying the global macros where these values are stored.

For example,

 . display "$S_DATE"
 14 Feb 2003

 . display "$S_TIME"

 . display "$S_TIME  $S_DATE"
 15:53:17  14 Feb 2003

The current date and time are also available as part of the c() class, see [P] creturn.

 . display c(current_date)
 14 Feb 2003

 . display c(current_time)

 . display "`c(current_time)' `c(current_date)'"
 15:56:32  14 Feb 2003

David Kantor suggests the following ado-file:

 *! version 1.0
 * Datetime procedure.  Just displays the date and time.
 * Good for use in logged sessions.
 * By David Kantor.  9-26-97
 version 7.0
 program define datetime 
 disp "DateTime: $S_DATE $S_TIME"

It is then easy to include datetime in your do-files.





The Stata Blog: Not Elsewhere Classified Find us on Facebook Follow us on Twitter LinkedIn Google+ YouTube
© Copyright 1996–2016 StataCorp LP   •   Terms of use   •   Privacy   •   Contact us