-1

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'>
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 2
    Does this answer your question? [Convert a timedelta to days, hours and minutes](https://stackoverflow.com/questions/2119472/convert-a-timedelta-to-days-hours-and-minutes) – cbo Sep 29 '22 at 08:40
  • that do help, thanks, now I solve my problem, appreciate! –  Oct 04 '22 at 01:14

2 Answers2

1

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
Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
-1

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

j ton
  • 229
  • 9