-1

I want to find all dates between 2 dates the first date is unique_dates[0] the value of unique_dates[0] is 2021-08-30 and the second date is datetime.date.today()

unique_dates = list({a.date for a in attendances})
date = datetime.date.today()

How to do this ?

I'mahdi
  • 23,382
  • 5
  • 22
  • 30

1 Answers1

1

try this:

import datetime

real_date1 = datetime.datetime.strptime(str(unique_dates[0]), '%Y-%m-%d')
real_date2 = datetime.datetime.today()
date_range =  real_date2 - real_date1
dates = list()
for days in range(1,date_range.days+1):
    dates.append((real_date1 + datetime.timedelta(days)).strftime('%d/%m/%Y') )

print( dates)

output:

['31/08/2021', '01/09/2021', '02/09/2021', '03/09/2021']
I'mahdi
  • 23,382
  • 5
  • 22
  • 30
  • @PathParakh, if real_date1 is datetome.date only insert value in real_date1, `real_date1 = your_data` – I'mahdi Sep 03 '21 at 10:53