create an array of dates starting from today, for 8 days in python

To create an array of dates starting from today for 8 days, we can use the datetime module, which provides classes to manipulate dates and times.

We can use the datetime.today() function to get the current date and time, and then add timedelta objects to it to get the date for the next 8 days.

Here's how to create an array of dates starting from today for the next 8 days:

main.py
from datetime import datetime, timedelta

# get today's date
today = datetime.today().date()

# create an empty array
date_array = []

# loop 8 times, starting from today
for i in range(8):
    # add 1 day to the current date
    next_date = today + timedelta(days=i)
    # append the next date to the array
    date_array.append(next_date)
    
# print the array of dates
print(date_array)
391 chars
18 lines

This will output an array of 8 date objects, starting from today's date and ending 7 days later. You can modify the loop range and the timedelta argument to generate dates for a different number of days.

gistlibby LogSnag