Announcement

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

  • Changing time format

    Hello,

    I would like to change the format of a date variable, timestamp. Its current format is 20180201032049. I want to change it to YYYY MM DD HH MM SS. So I use the code

    format timestamp %tcCCYYNNDDHHMMSS.

    This code turns 20180201032049 into 25990626032352. Can anyone see what I am doing wrong?

    Kind regards,
    Hulya Kocyigit

  • #2
    Its current format is 20180201032049
    I think your problem is that this is not merely the display format in which your variable is stored, it is the actual number that it is stored as. One way might be to do this:

    Code:
    tostring timestamp, gen(t_str) format(%14.0f)
    gen double t = clock(t_str, "YMDhms")
    format %tcCCYY_NN_DD_HH_MM_SS t
    Unlike the original variable timestamp, The variable t is a date that Stata understands and can work with using various date-time functions.

    Comment


    • #3
      Thank you very much. This answers my question perfect.

      Kind regards,
      Hülya

      Comment

      Working...
      X