1

have a variable I've set up

now = datetime.datetime.now()

I want to be able to set up a variable, yesterday, that just takes now and subtracts one day from it.

I'm sure that this is super-easy, but how do I do this?

fox
  • 11,694
  • 20
  • 47
  • 76
  • 2
    Possible duplicate: http://stackoverflow.com/questions/441147/how-can-i-subtract-a-day-from-a-python-date – squiguy Mar 19 '13 at 22:20

1 Answers1

7

You can use datetime.timedelta:

now = datetime.datetime.now()
yesterday = now - datetime.timedelta(days=1)
mipadi
  • 359,228
  • 81
  • 502
  • 469