1

This is the query i am trying to run in a python file

cur.execute(f"(select data_end_time from table;))
records = cur.fetchall()")
print(records[0])

This is the Output i am getting

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

Expected output

2020-07-06 17:00:00

records[0] contains value datetime.datetime(2020, 7, 6, 17, 0) and is of type tuple

Shabari nath k
  • 920
  • 1
  • 10
  • 23

1 Answers1

0

You have to use datetime.strftime for converting datetime object into string

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'