Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Datetime列在python中为Postgres表提供了意外的格式_Python_Sql_Python 3.x_Postgresql_Datetime - Fatal编程技术网

Datetime列在python中为Postgres表提供了意外的格式

Datetime列在python中为Postgres表提供了意外的格式,python,sql,python-3.x,postgresql,datetime,Python,Sql,Python 3.x,Postgresql,Datetime,这就是我试图在python文件中运行的查询 cur.execute(f"(select data_end_time from table;)) records = cur.fetchall()") print(records[0]) 这是我得到的输出 datetime.datetime(2020, 7, 6, 17, 0) 预期产量 2020-07-06 17:00:00 记录[0]包含值datetime.datetime(2020,7,6,17,0)并且是tuple类

这就是我试图在python文件中运行的查询

cur.execute(f"(select data_end_time from table;))
records = cur.fetchall()")
print(records[0])
这是我得到的输出

datetime.datetime(2020, 7, 6, 17, 0)
预期产量

2020-07-06 17:00:00

记录[0]包含值datetime.datetime(2020,7,6,17,0)并且是tuple类型的记录

您必须使用datetime.strftime将datetime对象转换为字符串

import datetime

x = datetime.datetime(2020, 7, 6, 17, 0)

print(x.strftime('%Y-%m-%d %H:%M:%S')

#output
'2020-07-06 17:00:00'

必须使用datetime.strftime将datetime对象转换为字符串

import datetime

x = datetime.datetime(2020, 7, 6, 17, 0)

print(x.strftime('%Y-%m-%d %H:%M:%S')

#output
'2020-07-06 17:00:00'

数据工作..错误:'tuple'对象没有属性'strftime'try x[0]…strftime(“%Y-%m-%d%H:%m:%S”)记录[0][0]。strftime(“%Y-%m-%d%H:%m:%S”)工作..数据工作..错误:'tuple'对象没有属性'strftime'try x[0]…strftime(“%Y-%m-%d%H:%m:%S”)记录[0][0]。strftime(“%Y-%m-%d%H:%m:%S”)工作..这没有回答我的问题..记录[0]包含值datetime。datetime(2020,7,6,17,0)是tuplePlease澄清:你的意思是它是一个包含datetime对象的元组吗?记录[0]是一个包含datetime的tuple类型,它里面有datetime对象。你是否尝试过
记录[0][0]。strftime(“%Y-%m-%d%H:%m:%s”)
?这并没有回答我的问题。记录[0]包含值datetime.datetime(2020,7,6,17,0),类型为tuplePlease clarify:您的意思是它是一个包含datetime对象的元组吗?记录[0]是一个包含datetime对象的tuple类型,您是否尝试过
记录[0][0]。strftime(“%Y-%m-%d%H:%m:%s”)