Subtracting days from date in Python

In my previous article, we have seen how to add days to a date object in python. Now we will see how to subtract days form date object using the datetime.timedelta() method. Here is an example.

## Subtracting days from date
import datetime

## Date object
date_original = datetime.date(2019, 7, 20)

## Days to subtract
days_to_add = 387

## Subtract
date_new = date_original - datetime.timedelta(days_to_add)

print("\n Original Date: ", date_original, "\n")
print("\n New Date: ", date_new, "\n")
Subtracting days from date in Python

Reference

Related Articles & Tools

Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.