11

When fetching rows from my database containing time ex 15:15:15 h/m/s. I get those in timedelta objects, i want them in time object so I later can combine them with a date object and get a datetime object.

for row in results:
    startDate = row['startDate']
    StartTime = row['startTime']
    myListStartDate.append(datestart)
    myListTimeStart.append(startTime)

When i put all the startTimes in a list and prints the list i get datetime.timedelta(0, 54900). So how do convert the timedelta to a time object so I later can compare it to other time objects.

1
  • Are you looking for something like this? timedelta. Commented Oct 5, 2015 at 23:51

1 Answer 1

12

Here's how I would do it.

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

Credit goes to this post.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.