Please can you help me to get the transformation right?
Original string information:
Code:
. describe treatmenttime
              storage   display    value
variable name   type    format     label      variable label
-----------------------------------------------------------------------------
treatmenttime   str19   %19s                  Treatment Time
. list treatmenttime in 1
     +---------------------+
     |       treatmenttime |
     |---------------------|
  1. | 2018-10-10 17:27:14 |
     +---------------------+
Code:
gen treatmenttime2= Clock(treatmenttime, "YMDhms")
. describe treatmenttime2
              storage   display    value
variable name   type    format     label      variable label
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
treatmenttime2  float   %9.0g   
. list treatmenttime2 in 1
     +----------+
     | treatm~2 |
     |----------|
  1. | 1.85e+12 |
     +----------+
. format treatmenttime2 %tC
. list treatmenttime2 in 1
     +--------------------+
     |     treatmenttime2 |
     |--------------------|
  1. | 10oct2018 17:27:21 |
     +--------------------+
2018-10-10 17:27:14
and got
10oct2018 17:27:21
after the transformation.
Furthermore, the actual difference between starting time and transformed time varies depending on the very content of the string between few seconds and minutes which is even more frustrating.
0 Response to Converting string to date/time variables fails somehow
Post a Comment