简体   繁体   中英

converting int to timestamp or any date format sql

I am pulling from a db and have a row that has a timestamp and I want it to show up as a date in my python script. Here is an example of the data

1422471599
1422471599
1422471599

Here is what I am trying to do in sql

convert(timestamp, cast(time as varchar(12)))

I would also be willing to try and convert this in python

You could use datetime.fromtimestamp :

from datetime import date

s = 1422471599

print(date.fromtimestamp(s)
2015-01-28
select timestamp 'epoch' + your_column *  interval '1 second' from your_table;

Source: valkrysa blog post

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM