A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Subtract a week (7 days) from a given date in Python
Q:

Subtract a week (7 days) from a given date in Python

0

Subtract a week (7 days)  from a given date in Python

Given:

given_date = datetime(2020, 2, 25)

Expected output:

2020-02-18

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

from datetime import datetime, timedelta

given_date = datetime(2020, 2, 25)
print("Given date")
print(given_date)

days_to_subtract = 7
res_date = given_date - timedelta(days=days_to_subtract)
print("New Date")
print(res_date)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now