I have a dataset that appears to have time in an “elapsed” format (possibly in SAS format, where time is expressed as number of seconds elapsed since Jan 1st 1960). In a sql query I would like to convert this to a timestamp or date format. Is there a nice, clean way to do this?
Something similar to the answer here, except I need it in psql, not Python:
Time and date on the basis of seconds elapsed since 1970 year
Here is a sample of my data:
time_var
-------------
1344444527000
1344448596000
1344455497000
1344445125000
Here is the type of query I’d like to make:
select
time_var
cast(time_var as timestamp) as mytimestamp,
cast(time_var as date) as mydatetime,
date(time_var) as mydate
from
source_dataset
;
Turns out my dataset is using UNIX timestamps, so the values are big integers (the extra zeros need to be stripped) and the time is from Jan 1st 1970. I obtained the following code from my boss to convert these: