Write a Python program to subtract Three days from current date


The program demonstrates how to get the date that is three days before the current date. Here's how the program works:

  • First, it imports the date and timedelta classes from the datetime module.
  • Then, it creates a date object representing the current date using the today() method of the date class.
  • It creates a timedelta object representing three days by subtracting timedelta(3) from the current date object.
  • It prints the current date and the date three days before the current date using the print() function.

The timedelta class is used to represent the difference between two dates or times. It can be used to perform arithmetic operations on dates, such as adding or subtracting days, weeks, or months from a date. In this program, we subtract three days from the current date to get the date that is three days before the current date.

Source Code

from datetime import date, timedelta
dt = date.today() - timedelta(3)
print("Current Date :",date.today())
print("Three days before Current Date :",dt)

Output

Current Date : 2022-09-24
Three days before Current Date : 2022-09-21

Example Programs