How do I print yesterdays date in python?

I need yesterdays date in YYYY-MM-DD

Thanks

asked 14 Dec '11, 10:46

fox's gravatar image

fox ♦♦
800162527
accept rate: 37%


This is how I would do it:

>>> import datetime as dt
>>> yesterday = dt.datetime.now() - dt.timedelta( days = 1 )
>>> print yesterday.strftime( '%Y-%m-%d' )
2011-12-13
link

answered 14 Dec '11, 10:50

Russell%20Ballestrini's gravatar image

Russell Ball...
1.3k232937
accept rate: 43%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×7
×1
×1
×1

Asked: 14 Dec '11, 10:46

Seen: 2,533 times

Last updated: 14 Dec '11, 10:50

powered by OSQA