[Python] TypeError: '>' not supported between instances of 'datetime.datetime' and 'str'

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to python date and time types.

    I have a date value.

    date = '2018-11-10 10:55:31+00:00'


    I need to check this date value is older than 90 days.

    I tried :

    from datetime import datetime
    from datetime import timedelta

    past = datetime.now() - timedelta(days=90)
    date = '2018-11-10 10:55:31+00:00'

    if past > date :
    print("This is older than 90 days")


    failing with the following error :
    TypeError: '>' not supported between instances of 'datetime.datetime' and 'str'

    This might be because the date format for 'past' and the date value which I passed is different.

    How can I come up with this ?

    Continue reading...

Compartilhe esta Página