0

Is there a way to deduct a specified number of months from a given date. So for example, if the day is 2006/02/27. Then I want to backtrack 3 months and find the months within this date and 3 months back. In this case, it would be Feb, Jan & dec. What I am really after is finding a range of months.

I can think of using timedelta and specifying 93 days (31 x 3). But this could potentially be a problem if its early month date. something like 01/03/2006 - 93 days will perhaps result in a date in november/2005, which will include march, Feb,Jan,Dec,Nov as months. But what I want is March,Feb and Jan

from datetime import datetime,timedelta
someDate = datetime(2006,2,27) 
newDate =someDate - timedelta(days = 3)
#someDate - 3months

Any ideas on how to solve?

imantha
  • 2,676
  • 4
  • 23
  • 46

0 Answers0