Earlier quoted context omitted.
>>> from datetime import datetime, timedelta >>> datetime.now() - (datetime.now() + timedelta(days=1)) datetime.timedelta(-2, 86399, 999969)
I’m not entirely sure what you were trying to demonstrate, but clearly the result of datetime.now() changes between the two invocations (it has microsecond precision). Try: >>> from datetime import datetime, timedelta >>> now = datetime.now() >>> now - (now + timedelta(days=1)) datetime.timedelta(-1)
That a timedelta can be represented in multiple ways is alone quite surprising but some of the representations that happen can be very confusing. I think the example I gave which represents "-1 day and a few microseconds" as "-2 days + 86399 milliseconds + 999969 microseconds" is very surprising and it commonly happens in practice.
For comparison, here's what postgres does:
postgres=> select now() - (now() + '12 milliseconds'::interval + '1 day'::interval);
?column?
-----------------------
-1 days -00:00:00.012
(1 row)