Q:

Add a week (7 days) and 12 hours to a given date using python programming

belongs to collection: Python Date and Time Exercises

0

Add a week (7 days) and 12 hours to a given date

Given:

# 2020-03-22 10:00:00
given_date = datetime(2020, 3, 22, 10, 0, 0)

Expected output:

2020-03-29 22:00:00

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, 3, 22, 10, 00, 00)
print("Given date")
print(given_date)

days_to_add = 7
res_date = given_date + timedelta(days=days_to_add, hours=12)
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)

Print current time in milliseconds using python pr... >>
<< Find the day of the week of a given date using pyt...