Skip to content

Instantly share code, notes, and snippets.

@gccpacman
Last active October 9, 2015 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gccpacman/9354678973bd2fa9e66d to your computer and use it in GitHub Desktop.
Save gccpacman/9354678973bd2fa9e66d to your computer and use it in GitHub Desktop.
Python 基础

How do I calculate number of days betwen two dates using Python?

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 = d0 - d1
print delta.days

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment