Create 12 Fixed Date Specified Date Given Period in python


Write a Python program to create 12 fixed dates from a specified date over a given period. The difference between two dates will be 20


The program starts by importing the datetime module from the Python Standard Library. Next, a datetime.date object is created with the year 2022, month 10, and day 1. This object is assigned to the variable date. A string "Starting Date: {d}" is printed to the console, where {d} is replaced by the value of the date variable.

Next, a for loop is used to iterate 12 times. On each iteration of the loop, a datetime.timedelta object is created with an argument of 20 days. This timedelta object is then added to the date variable to create a new datetime.date object representing the date 20 days in the future. The new date is then printed to the console with the string "Next 12 days : {d}", where {d} is replaced by the value of the new date. So, this program generates the next 12 dates, starting from the specified date, that are 20 days apart from each other.

Source Code

import datetime
date = datetime.date(2022,10,1)
print('Starting Date: {d}'.format(d=date))
print("Next 12 days :")
for _ in range(12):
	date=date+datetime.timedelta(days=20)
	print('{d}'.format(d=date))

Output

Starting Date: 2022-10-01
Next 12 days :
2022-10-21
2022-11-10
2022-11-30
2022-12-20
2023-01-09
2023-01-29
2023-02-18
2023-03-10
2023-03-30
2023-04-19
2023-05-09
2023-05-29

Example Programs