-1
+-----------+----------+
| from_time | to_time  |
+-----------+----------+
| 09:00:00  | 22:00:00 |
+-----------+----------+
1 row in set (0.00 sec)

that is my actual SQL table which is in Hours:minutes:seconds format. when I query with select from_time, to_time from Tollapp_configure;, in django I got the out put as ((datetime.timedelta(0, 32400), datetime.timedelta(0, 79200)),).

How can I convert ((datetime.timedelta(0, 32400), datetime.timedelta(0, 79200)),) into actual Hours minutes and seconds (22:00:00 format).

My django model looks like this:

class Configure (models.Model):
    from_time = models.TimeField()
    to_time = models.TimeField()
Peter Sobhi
  • 2,542
  • 2
  • 22
  • 28
  • `print(datetime.timedelta(0, 32400))` prints `9:00:00` what exactly is your problem? – Patrick Artner May 21 '18 at 12:48
  • 1
    Possible duplicate of [Python: How do I get time from a datetime.timedelta object?](https://stackoverflow.com/questions/764184/python-how-do-i-get-time-from-a-datetime-timedelta-object) – George K May 21 '18 at 12:51
  • Possible duplicate of [Python format timedelta to string](https://stackoverflow.com/questions/538666/python-format-timedelta-to-string) – Patrick Artner May 21 '18 at 12:53

1 Answers1

0

Here's a solution:

Convert the timedelta into a date using python

>>> import datetime
>>> startTime = datetime.timedelta(0, 54915)
>>> startTime = (datetime.datetime.min + startTime).time()
>>> startTime
datetime.time(15, 15, 15)

Get date in format through SQL

SELECT STRFTIME('%Y-%m-%d', datetime) FROM your_table;

Source: How to retrieve the Date part out of a Datetime result column in SQLite?

Hope this helps.

George K
  • 481
  • 2
  • 13