create a weekly schedule in python

main.py
# Import the necessary libraries
from datetime import datetime, timedelta

# Function to create a weekly schedule
def create_weekly_schedule(start_date, end_date):
    current_date = start_date
    while current_date <= end_date:
        print(f"Week of {current_date}")
        for i in range(7):
            print(f"{current_date.strftime('%A')}")
            current_date += timedelta(days=1)
        print()
        current_date += timedelta(days=(7-current_date.weekday()))

# Define the start and end dates for the weekly schedule
start_date = datetime(2023, 1, 1)  # January 1st, 2023
end_date = datetime(2023, 1, 31)  # January 31st, 2023

# Call the function with the specified dates
create_weekly_schedule(start_date, end_date)
738 chars
21 lines

This Python code defines a function that creates a weekly schedule starting from a specified start date and ending at a specified end date. The function iterates through each week within the provided date range, printing the days of the week for each week.

related categories

gistlibby LogSnag