Announcement

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

  • Yesterday using c(current_date)

    I thought it is fairly simple but I am not able to produce yesterday's date automatically. I want to save yesterday's date in a local macro using c(current_date), such as the following which does not work:

    Code:
    local yesterday = c(current_date)-1
    di "`yesterday'"

  • #2
    It's because c(current_date) is a string.
    Code:
    local yesterday : display %tdCY-N-D date("`c(current_date)'", "DMY") - 1
    display "`yesterday'"

    Comment


    • #3
      c(current_date) is a string, as creturn list affirms. So, to do arithmetic on it, even subtracting 1, you could push it through daily() or date() first, just like any other string containing a daily date, where help datetime explains.

      You don't say exactly what you to see or to store but you have choices ranging between a numeric date (origin 1 January 1960) and a string using any daily date display format of your choice.

      You know to assign to a local macro.

      Code:
      . cret li
      
      System values
      
          --------------------------------------------------------------------------------------
              c(current_date) = "20 Sep 2018"
      
      [output deleted] 
      
      . di daily("`c(current_date)'", "DMY") - 1
      21446
      
      . di %td daily("`c(current_date)'", "DMY") - 1
      19sep2018

      Comment

      Working...
      X