Announcement

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

  • Help with clock() function

    Dear all,

    I had a time variable in string format. I use clock() function to change it to Stata readable format.
    Here is the problem:
    RegistrationDate="2022-01-01 00:00:00" --> RegTime=31dec2021 23:59:33
    My code is:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str19 RegistrationDate
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    "2022-01-01 00:00:00"
    end
    g RegTime = clock(RegistrationDate, "YMD hms")
    Thanks in advance,
    Best regards,
    Cu

  • #2
    You should use a double to hold date-times.

    Code:
     
     g double RegTime = clock(RegistrationDate, "YMD hms")
    See

    Code:
    help datetime
    where this point is flagged repeatedly.

    Comment

    Working...
    X