date1 = datetime.datetime(2012, 10, 10, 10, 15, 44)
date2 = datetime.datetime(2012, 10, 17, 8, 45, 38)
roundedA = date2.replace(second = 0, microsecond = 0)
print roundedA
roundedB = date1.replace(second = 0, microsecond = 0)
print roundedB
minutes = (roundedA - roundedB).min
print minutes
Result is:
-999999999 days, 0:00:00
I want to count 2 different dates differences. I subtracted above, but it does not give me what I want. How to do subtract two dates and get the result in minutes or hours.
The timedelta.min attribute does not represent minutes- it means the smallest possible timedelta (see here). If you want to get it in minutes, you can do:
d = roundedA - roundedB
minutes = d.days * 1440 + d.seconds / 60
This is because only seconds and days are stored internally in timedelta.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With