Announcement

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

  • converting string datetime to numeric

    Can anyone help with code on converting this string datetime to numeric?
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str16 date
    "1/02/2017 8:38"  
    "1/03/2021 6:50"  
    "12/03/2018 8:20" 
    "12/10/2020 10:00"
    "13/06/2018 9:20" 
    end
    Thanks

  • #2
    Your format is standard for datetime strings. Therefore, browsing through the datetime functions would easily lead you to the solution.

    Code:
    help datetime
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str16 date
    "1/02/2017 8:38"  
    "1/03/2021 6:50"  
    "12/03/2018 8:20"
    "12/10/2020 10:00"
    "13/06/2018 9:20"
    end
    
    gen double wanted= clock(date, "DMYhm")
    format wanted %tc
    Res.:

    Code:
    . l
    
         +---------------------------------------+
         |             date               wanted |
         |---------------------------------------|
      1. |   1/02/2017 8:38   01feb2017 08:38:00 |
      2. |   1/03/2021 6:50   01mar2021 06:50:00 |
      3. |  12/03/2018 8:20   12mar2018 08:20:00 |
      4. | 12/10/2020 10:00   12oct2020 10:00:00 |
      5. |  13/06/2018 9:20   13jun2018 09:20:00 |
         +---------------------------------------+

    Comment

    Working...
    X