Write a Python program to print next 5 days starting from today


This program is written in Python and performs the following tasks:

  • It imports the datetime module to work with dates and times.
  • It creates a datetime object called base that represents the current date and time.
  • It uses a for loop to iterate over a range of 5 days starting from today.
  • Inside the loop, it adds a timedelta object of x days to the base object and prints the resulting date and time.

Therefore, the output of this program is a list of 5 dates, starting from today and each consecutive date increasing by one day. The output format is in the default format of datetime objects.

Source Code

import datetime
base = datetime.datetime.today()
for x in range(0, 5):
      print(base + datetime.timedelta(days=x))

Output

2022-09-24 14:47:12.710649
2022-09-25 14:47:12.710649
2022-09-26 14:47:12.710649
2022-09-27 14:47:12.710649
2022-09-28 14:47:12.710649

Example Programs