[英]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. 我正在从数据库中提取数据,并且有一个带有时间戳的行,并且希望它在我的python脚本中显示为日期。 Here is an example of the data 这是数据的一个例子
1422471599
1422471599
1422471599
Here is what I am trying to do in sql 这是我想在SQL中做的
convert(timestamp, cast(time as varchar(12)))
I would also be willing to try and convert this in python 我也愿意尝试在python中进行转换
You could use datetime.fromtimestamp : 您可以使用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 资料来源: valkrysa博客文章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.