Generation

generate functionTue, 20 Dec 2022

Change the date_range function to return a list of all dates between start and end instead of return somelist 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')) return somelist 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): result = [] if start_date > end_date: return result else: while start_date <= end_date: result.append(start_date.strftime('%Y-%m-%d')) start_date += td(days=1) return result date_range('1992-09-01', '1992-09-04') # ['1992-09-01', '1992-09-02', '1992-09-03', '1992-09-04']

Questions about programming?Chat with your personal AI assistant