[Python] Python generating a list of dates between two dates

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    I want to generate a list of dates between two dates and store them in a list in string format. This list is useful to compare with other dates I have.

    My code is given below:

    from datetime import date, timedelta

    sdate = date(2019,3,22) # start date
    edate = date(2019,4,9) # end date

    def dates_bwn_twodates(start_date, end_date):
    for n in range(int ((end_date - start_date).days)):
    yield start_date + timedelta(n)
    print(dates_bwn_twodates(sdate,edate))


    My present output:

    <generator object dates_bwn_twodates at 0x000002A8E7929410>


    My expected output:

    ['2019-03-22',.....,'2019-04-08']


    Something wrong in my code.

    Continue reading...

Compartilhe esta Página