Announcement

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

  • Date variable to String

    Hello all,

    I have a date variable in the form of ddmmyyyy, for example :31oct2019 . This date variable is a numeric (long) variable. I would like to convert it to a string variable but when I do that, the format is messed up. For example, the date 31oct2019 becomes 21853. Anyone know how to get the format back to ddmmyyyy?

    Thanks!

  • #2

    Code:
    clear
    input float date
    21853
    end
    
    gen wanted= string(date, "%tdDmCY")
    
    l
    Res.:

    Code:
    . l
    
         +-------------------+
         |  date      wanted |
         |-------------------|
      1. | 21853   31Oct2019 |
         +-------------------+
    
    .

    I do not know what you need to do with a string date, but just in case you want to change the display format, I will include code for that too.

    Code:
    format date %tdDmCY
    Last edited by Andrew Musau; 25 Apr 2022, 06:42.

    Comment


    • #3
      Great thanks Andrew that works

      Comment

      Working...
      X