Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: working with timestamps with milliseconds

From   "Martin Weiss" <>
To   <>
Subject   st: RE: working with timestamps with milliseconds
Date   Sun, 21 Feb 2010 10:00:33 +0100


You requested -format- %tc, and the -help dates_and_times- gives you the
following advice:

                 | DO NOT FORGET                                 |
                 |                                               |
                 | %tc and %tC values MUST BE stored as doubles. |
                 | Doing so is your responsibility, not Stata's. |


-----Original Message-----
[] On Behalf Of David Souther
Sent: Sonntag, 21. Februar 2010 02:30
Subject: st: working with timestamps with milliseconds

I couldn't find a solution to this in the Statalist archives, and this
may be in the dates/times help file but I've read through it a couple
of time and cannot find (or probably don't understand this file enough
to find) the solution for how to work with milliseconds.
Every time I format a timestamp that includes the MDY along with
hours, minutes, seconds and milliseconds, the seconds/milliseconds are
off by a minute or so.  I did see the section on leap seconds, but I"m
not sure how that plays into my example and if there is a way to just
show and work with the exact timestamp that I input into Stata.
Here's what I do

inp str30 time
"1-22-2007 3:44:22"
"1/23/2008 02:23:11.11"

gen time2 = clock(time, "MDY hms")
format time2 %tC

gen d2 = clock("2/22/2002 14:22:33.232", "MDY hms")
format d2 %tc

This gives me --

     |                  time                time2                   d2 |
  1. |     1-22-2007 3:44:22   22jan2007 03:43:35   22feb2002 14:23:02 |
  2. | 1/23/2008 02:23:11.11   23jan2008 02:23:17   22feb2002 14:23:02 |
Notice that the time changed in from things like 3:44:22  to 3:43:35.

I tried using %tC as well.  I use Stata 11 on Windows.  Any hints?


*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index