Subtract 2 weeks from a full date in Pyhton

Asked

Viewed 741 times

5

I’m thinking a date in this format:

time.strftime("%d/%m/%Y") // 00/00/0000

I want to subtract two weeks from that date, but I don’t know how to do it.

1 answer

8

You can use the timedelta and pass as a parameter the number of days you want to replace from a date.

from datetime import datetime, timedelta

hoje = datetime.today() - timedelta(days=14)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.