Top-rated recipes tagged "month"http://code.activestate.com/recipes/tags/month/top/2010-06-25T18:41:19-07:00ActiveState Code Recipessubtract or add a month to a datetime.date or datetime.datetime (Python) 2010-06-25T18:41:19-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577274-subtract-or-add-a-month-to-a-datetimedate-or-datet/ <p style="color: grey"> Python recipe 577274 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/month/">month</a>). </p> <p>Adding or subtracting a month to a Python <code>datetime.date</code> or <code>datetime.datetime</code> is a little bit of a pain. Here is the code I use for that. These functions return the same datetime type as given. They preserve time of day data (if that is at all important to you).</p> <p>See also: </p> <ul> <li><a href="http://code.activestate.com/recipes/476197/">Recipe 476197</a>: First / Last Day of the Month.</li> <li><a href="http://packages.python.org/MonthDelta/">monthdelta module</a></li> </ul>