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" <[email protected]>
To   [email protected]
Subject   Re: st: convert from unix time to calendar time
Date   Thu, 26 Sep 2002 13:57:40 -0400

Karim,

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")
3653

so

replace daystamp=daystamp+3653

and

format daystamp %d



//Jesper



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!

Thanks

Karim

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jesper B. S�rensen
Richard S. Leghorn (1939) Associate Professor of Strategic Management
Sloan School of Management
Massachusetts Institute of Technology
E52-581
Cambridge, MA 02142
http://web.mit.edu/sorensen/www/
(617) 253 7945  -- voice
(617) 253 2660  -- fax

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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