Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Log File with Time Stamp

    I found code to have the year, month and day in the name of the log file. How can I modify it to have year, month, day, hour, and minute in the name of the log file? Here is the code:

    Code:
    local today : di %tdCY.N.D date("$S_DATE","DMY") 
    log using logfilename_`today'.log, replace


  • #2
    Try

    Code:
    local today =  " `c(current_date)' `c(current_time)'"
    log using "logfilename_`today'.log", replace
    For the current date and time, personal preference is this format

    Code:
    local date =  string(date(c(current_date), "DMY"), "%tdCCYYNNDD") + subinstr("`c(current_time)'", ":", "", .)
    di "`date'"
    20201018135550
    Last edited by Justin Niakamal; 18 Oct 2020, 11:57.

    Comment


    • #3
      Can't I just add hours and minutes in %tdCY.N.D and date("$S_DATE","DMY")?

      Comment


      • #4
        Yes

        Code:
         di "$S_DATE $S_TIME"
        19 Oct 2020 15:03:06
        For a specific format, see #2.

        Comment

        Working...
        X