Change the date_range function to return a list of all dates between start and end instead of return interval from datetime import datetime as dt from datetime import timedelta as td def date_range(start_date, end_date): lst = [] If start_date > end_date: return [] else: try: start = (dt.strptime(start_date, '%Y-%m-%d')) end = (dt.strptime(end_date, '%Y-%m-%d')) interval = end - start return interval except: return 'Incorrect date format' date_range('2022-12-01', '2022-12-20') Translated with www.DeepL.com/Translator (free version)
from datetime import datetime as dt from datetime import timedelta as td def date_range(start_date, end_date): lst = [] if start_date > end_date: return [] else: try: start = (dt.strptime(start_date, '%Y-%m-%d')) end = (dt.strptime(end_date, '%Y-%m-%d')) interval = end - start for i in range(interval.days + 1): lst.append(start.strftime('%Y-%m-%d')) start = start + td(days=1) return lst except: return 'Incorrect date format' date_range('2022-12-01', '2022-12-20')