date_1 = datetime.datetime.strptime(start_date, "%m/%d/%y")
end_date = date_1 + datetime.timedelta(days=10)
# Timedelta function demonstration
from datetime import datetime, timedelta
# Using current time
time_for_now = datetime.now()
# printing initial_date
print("initial_date", str(time_for_now))
# Calculating future dates
# for two years
future_date_after_1yr = time_for_now + timedelta(days=365)
future_date_after_5days = time_for_now + timedelta(days=5)
# printing calculated future_dates
print('future_date_after_1yr:', str(future_date_after_1yr))
print('future_date_after_5days:', str(future_date_after_5days))
date = datetime.datetime(2003,8,1,12,4,5)
for i in range(5):
date += datetime.timedelta(days=1)
print(date)
import datetime
delta = datetime.timedelta(
days=50,
seconds=27,
microseconds=10,
milliseconds=29000,
minutes=5,
hours=8,
weeks=2
)
new_datetime = datetime.now() + delta