Astrodude11 Astrodude11 - 1 year ago 106
MySQL Question

Convert datetime.timedelta Object to HH:MM

My database table has a column whose datatype is

, so when queried it returns
. However, using Python it returns
(datetime.timedelta(0, 57360),)

This is obviously the time difference in seconds. How do I convert the returned object into a string in the format

Answer Source

That's how you can print the time:

import datetime

delta = datetime.timedelta(0, 57360)
sec = delta.seconds
hours = sec // 3600
minutes = (sec // 60) - (hours * 60)
print(hours, ':', minutes)

you can also print the time with seconds by

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download