Skip to content

Instantly share code, notes, and snippets.

@fatosmorina
Created March 28, 2021 18:29
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 fatosmorina/3a555c1086c34d156420ce025259846e to your computer and use it in GitHub Desktop.
Save fatosmorina/3a555c1086c34d156420ce025259846e to your computer and use it in GitHub Desktop.
from datetime import datetime
first_date = datetime(2021, 3, 26)
second_date = datetime(2020, 12, 26)
month_difference = first_date.month - second_date.month # -3
year_difference = first_date.year - second_date.year # 1
month_difference = month_difference + 12 * year_difference # -9 + 12 * 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment