Date difference in days

Python, Date · Oct 28, 2020

Calculates the day difference between two dates.

  • Subtract start from end and use datetime.timedelta.days to get the day difference.
def days_diff(start, end):
  return (end - start).days
from datetime import date

days_diff(date(2020, 10, 25), date(2020, 10, 28)) # 3

More like this

  • Date difference in months

    Calculates the month difference between two dates.

    Python, Date · Oct 28, 2020

  • Days ago

    Calculates the date of n days ago from today.

    Python, Date · Oct 28, 2020

  • Days from now

    Calculates the date of n days from today.

    Python, Date · Oct 28, 2020