cur.execute('Select ts from testtable where nd_a>%s and nd_b>%s and nd_c>%s',(medA,medB,medC))
result_ts=cur.fetchall()
print (result_ts)
当我得到输出时,它看起来像这样:
((datetime.datetime(2020, 1, 1, 1, 15, 24),), (datetime.datetime(2020, 1, 1, 1, 15, 38),), (datetime.datetime(2020, 1, 1, 1, 16, 30),), (datetime.datetime(2020, 1, 1, 1, 16, 37),), (datetime.datetime(2020, 1, 1, 1, 17, 8),), (datetime.datetime(2020, 1, 1, 1, 17, 14),))
当我需要这种格式的输出日期时:YYYY-MM-DD HH:MM:SS
如何将其更改为这种格式 View ?
最佳答案
你可以这样做:
cur.execute('Select ts from testtable where nd_a>%s and nd_b>%s and nd_c>%s',(medA,medB,medC))
result_ts=cur.fetchall()
for result in result_ts:
print(result[0])
这将打印:
2020-01-01 01:15:24
2020-01-01 01:15:38
2020-01-01 01:16:30
2020-01-01 01:16:37
2020-01-01 01:17:08
2020-01-01 01:17:14
关于python - 从Python中的SQL查询中选择时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59651401/