4

How can I get previous month and year using python. Is it possible to get it using datetime module

I want to get it like following example

 current:  2012-03      prev   2012-02
 current:  2012-01      prev   2011-12
user2412872
  • 43
  • 1
  • 3
  • Welcome to Stack Overflow! It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, stack traces, compiler errors - whatever is applicable). The more detail you provide, the more answers you are likely to receive. – Martijn Pieters May 23 '13 at 09:15

1 Answers1

3

use

 date(2012,3,1)+relativedelta(years=-1)

see http://labix.org/python-dateutil

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81