Announcement

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

  • fix dates

    Hello everyone,

    Can someone help me with converting the dates that I have in my data. Here, I have dates in the form of "18.11.2020 00:48:07" and I want to convert to something like "18nov2020 00:48:07". Also, The original variable is string can I convert it to float?

    Thank you for your time

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str19 open_date
    "18.11.2020 00:48:07"
    "18.11.2020 00:48:07"
    end

  • #2
    Thank you for providing the data example.

    Code:
    gen want = clock(open_date, "DMYhms")
    format want %tc
    list
    Results:

    Code:
         +------------------------------------------+
         |           open_date                 want |
         |------------------------------------------|
      1. | 18.11.2020 00:48:07   18nov2020 00:48:07 |
      2. | 18.11.2020 00:48:07   18nov2020 00:48:07 |
         +------------------------------------------+
    There is a lot to learn about internal representation of dates and times in Stata. It is well worth the time to read the manual for datetimes. See -help datetime- and especially the PDF documentation (linked at the top).

    Comment


    • #3
      You should always use double for date-times, and never float. That isn't obviously biting in #2 but it is much repeated advice, e.g. at

      Code:
      help datetime

      Comment


      • #4
        Thank you so much Leonardo and Dr Nick!

        Comment

        Working...
        X