Announcement

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

  • clock() mask %tc not accurate

    Hi all,

    I have a set of dates that are strings which look like this:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str22 txndate
    "01/01/2019 07:12:42 AM"
    "01/01/2019 08:38:22 AM"
    "01/01/2019 08:31:11 AM"
    "01/01/2019 11:46:34 AM"
    "01/01/2019 11:58:35 AM"
    "01/01/2019 12:08:02 PM"
    "01/01/2019 06:11:21 AM"
    "01/01/2019 11:09:52 AM"
    "01/01/2019 12:46:47 PM"
    "01/01/2019 10:07:14 AM"
    "01/01/2019 02:31:08 PM"
    "01/01/2019 02:19:07 PM"
    "01/01/2019 03:21:04 PM"
    "01/01/2019 02:45:27 PM"
    "01/01/2019 03:29:12 PM"
    "01/01/2019 05:20:54 PM"
    "01/01/2019 03:09:28 PM"
    "01/01/2019 10:49:01 AM"
    "01/01/2019 03:12:23 PM"
    "01/01/2019 02:27:21 PM"
    end
    And I would like to get them into a datetime format. The line of code I'm using to do this is:
    Code:
    gen correctdate = clock(txndate, "MDYhms")
    which generates this:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float correctdate
     1.861946e+12
     1.861951e+12
    1.8619506e+12
    1.8619624e+12
     1.861963e+12
    1.8619637e+12
    1.8619422e+12
    1.8619602e+12
     1.861966e+12
    1.8619564e+12
    1.8619723e+12
    1.8619716e+12
    1.8619753e+12
     1.861973e+12
    1.8619758e+12
    1.8619825e+12
    1.8619746e+12
     1.861959e+12
    1.8619748e+12
     1.861972e+12
    end
    But then I would like to use a mask to see what the time is, not just what the number of milliseconds since 01jan1960 are. For this I'm using the code:
    Code:
    format %tc correctdate
    However, this shows values that are slightly off (like, by under 60 seconds) from what the true value in the string txndate was. I don't know how to show what the masked data looks like using dataex, but for example, the first observation originally is "01/01/2019 07:12:42 AM", but when made into datetime and then masked, it shows as "01jan2019 7:11:57". The second observation is originally "01/01/2019 08:38:22 AM" but I put it through my two lines of code shown here, it shows up as "01jan2019 8:39:20". The error isn't even the same, the first observation has a discrepancy of 45 seconds and the second observation has a discrepancy of 58 seconds.

    Using the mask %tC doesn't yield more accurate results.

    What's up here? How do I get the raw datetime value to be masked as something that's accurate to the original txndate string?

  • #2
    Maybe try
    Code:
    gen correctdate = clock(txndate, "MDYhms")
    Code:
    generate double correctdate = clock(txndate, "MDYhms")

    Comment

    Working...
    X