Skip to main content
Add parentheses to avoid `SyntaxError: Missing parentheses in call to 'print'. Did you mean print(delta.days)?` in Python 3.7.4, and add links to satisfy edit length requirement
Source Link

If you have two date objects, you can just subtract them, which computes a timedelta object.

from datetime import date d0 = date(2008, 8, 18) d1 = date(2008, 9, 26) delta = d1 - d0 print (delta.days) 

The relevant section of the docs: https://docs.python.org/library/datetime.html.

See this answer for another example.

If you have two date objects, you can just subtract them.

from datetime import date d0 = date(2008, 8, 18) d1 = date(2008, 9, 26) delta = d1 - d0 print delta.days 

The relevant section of the docs: https://docs.python.org/library/datetime.html.

If you have two date objects, you can just subtract them, which computes a timedelta object.

from datetime import date d0 = date(2008, 8, 18) d1 = date(2008, 9, 26) delta = d1 - d0 print(delta.days) 

The relevant section of the docs: https://docs.python.org/library/datetime.html.

See this answer for another example.

[Edit removed during grace period]
Source Link
Michael M
  • 9k
  • 2
  • 39
  • 55
added 1 character in body
Source Link
coder
  • 4.5k
  • 2
  • 17
  • 22

If you have two date objects, you can just subtract them.

from datetime import date d0 = date(2008, 8, 18) d1 = date(2008, 9, 26) delta = d1 - d0 print delta.days 

The relevant section of the docs: https://docs.python.org/library/datetime.html.

If you have two date objects, you can just subtract them.

from datetime import date d0 = date(2008, 8, 18) d1 = date(2008, 9, 26) delta = d1 - d0 print delta.days 

The relevant section of the docs: https://docs.python.org/library/datetime.html

If you have two date objects, you can just subtract them.

from datetime import date d0 = date(2008, 8, 18) d1 = date(2008, 9, 26) delta = d1 - d0 print delta.days 

The relevant section of the docs: https://docs.python.org/library/datetime.html.

edited body
Source Link
willeM_ Van Onsem
  • 481.8k
  • 33
  • 483
  • 624
Loading
Code formatting
Source Link
Dana
  • 33.1k
  • 17
  • 65
  • 73
Loading
Source Link
Dana
  • 33.1k
  • 17
  • 65
  • 73
Loading