0

When I subtract start time from end time, I get 10 days, 7:39:11 as the answer whereas when end time is subtracted from start time, the answer is -11 days, 16:20:49. Why is this so? The result should be the same with a negative sign, no?

import datetime

datetime_start = datetime.datetime(2021, 6, 13, 3, 31, 47, 466744)
datetime_end = datetime.datetime(2021, 6, 23, 11, 10, 58, 466744)

date_diff = datetime_end - datetime_start
print(type(date_diff))
print(date_diff)

date_diff = datetime_start - datetime_end
print(type(date_diff))
print(date_diff)
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • Maybe this answer helps? [Negative time difference in Pandas](https://stackoverflow.com/q/67637790/15740324) – Standard_101 Jun 23 '21 at 09:08
  • 1
    The point being, it goes back to -11 days and then adds the hours. So the behavior is correct, just our interpretation being different. – Standard_101 Jun 23 '21 at 09:09
  • 1
    see also [Python timedelta object with negative values](https://stackoverflow.com/q/46803405/10197418) – FObersteiner Jun 23 '21 at 09:11

0 Answers0