datetime.timedelta dates difference result converting to all days or minutes

Question:

How can I make my datetime.timedelta result shows all in days or minutes?

My expected output is:

minute left: 7023 min
days left: 5.002 day

My code:

aaa = "2017-09/19 07:11:00"
bbb = "2017-09/24 07:14:00"

result = parser.parse(bbb) - parser.parse(aaa)

print(result)
print(type(result))

The output:

5 days, 0:03:00         
<class 'datetime.timedelta'>
Asked By: 俠客行

||

Answers:

you need to convert to seconds and then convert seconds to minutes/hours

result = parser.parse( bbb) -parser.parse( aaa)

seconds = result.total_seconds()
minutes = seconds/60
hours = minutes/60
Answered By: Joran Beasley

solved code: (thanks for @Joran Beasley contributing )

from dateutil import parser
import datetime,time
aaa= "2017-09/19 07:11:00"
bbb= "2017-09/24 07:14:00"

result = parser.parse( bbb) -parser.parse( aaa)
seconds = result.total_seconds()

minutes = seconds/60
hours = minutes/60

print(result)
print(type(result))
print(minutes)
print(hours)

The result output:

5 days, 0:03:00
<class ‘datetime.timedelta’>
7203.0
120.05

Answered By: j ton
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.