【发布时间】:2016-09-21 07:30:00
【问题描述】:
我正在尝试在 python 中的以下方法中为时间戳添加几个小时
def add_hours(date, hour, duration):
conn = database_connect()
cur = conn.cursor()
val = None
start_time = date+" "+hour+":00:00"
try:
cur.execute("""SELECT timestamp %s + interval '%s hour' """,(start_time, duration))
val = cur.fetchall()
except:
print("fetcherror")
cur.close()
conn.close()
return val
日期和小时已连接到时间戳
(它看起来像一个SQL时间戳值:2016-5-24 18:00:00)
我查看了此处提供的 postgreSQL 文档: http://www.postgresql.org/docs/8.0/static/functions-datetime.html 并直接测试查询(它工作正常) 显然我的错误在于 python 处理查询,但我不知道它是什么。
我不明白什么?
【问题讨论】:
-
您使用哪个版本的 PostgreSQL?在链接中,您指的是恐龙时代的 8.0 版。
标签: python sql postgresql time timestamp