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 ♦♦
536162020
accept rate: 33%


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.1k222834
accept rate: 37%

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:

×6
×1
×1
×1

Asked: 14 Dec '11, 10:46

Seen: 623 times

Last updated: 14 Dec '11, 10:50

powered by OSQA