[Python] Difference between two dates in Python

Discussão em 'Python' iniciado por Stack, Agosto 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have two different dates and I want to know the difference in days between them. The format of the date is YYYY-MM-DD.

    I have a function that can ADD or SUBTRACT a given number to a date:

    def addonDays(a, x):
    ret = time.strftime("%Y-%m-%d",time.localtime(time.mktime(time.strptime(a,"%Y-%m-%d"))+x*3600*24+3600))
    return ret


    where A is the date and x the number of days I want to add. And the result is another date.

    I need a function where I can give two dates and the result would be an int with date difference in days.

    Continue reading...

Compartilhe esta Página