Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: convert from unix time to calendar time

From   "Jesper B. Sorensen" <sorensen@MIT.EDU>
Subject   Re: st: convert from unix time to calendar time
Date   Thu, 26 Sep 2002 13:57:40 -0400


unless I am mssing something, you just need to convert it into days since Jan 1 1960, and then use Stata's date functions.

gen daystamp=timestamp/(24*60*60)

-- daystamp is now days since 1/1/1970.

now compute the n of days between 1/1/1960 and 1/1/1970.

. di date("1/1/1970","mdy")


replace daystamp=daystamp+3653


format daystamp %d


At 10:56 AM 9/26/2002 -0400, you wrote:

hello all,

I have some data (lots actually!) in which each record has a unix time
stamp (meaning epoch starting January 1, 1970 in seconds).  I would like
to convert this into a more useful calendar date and time.  Before I
write my own do file I was wondering if any one has come across this
problem before and found an easy way to solve it.  Solving it requires
converting seconds into the actual time, day, month year --> thus today,
September 26, 2002 at 10.30 am would convert to 1033036225 in unix time
(indicating how many seconds have elapsed since Jan 1, 1970).

Appreciate any help!



*   For searches and help try:
Jesper B. Sørensen
Richard S. Leghorn (1939) Associate Professor of Strategic Management
Sloan School of Management
Massachusetts Institute of Technology
Cambridge, MA 02142
(617) 253 7945  -- voice
(617) 253 2660  -- fax

*   For searches and help try:

© Copyright 1996–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index