Skip to content

Instantly share code, notes, and snippets.

@vvoody
Created October 19, 2010 02:44
Show Gist options
  • Save vvoody/633516 to your computer and use it in GitHub Desktop.
Save vvoody/633516 to your computer and use it in GitHub Desktop.
import datetime
# I wanna create some thing in advance monthly, so I need to know the next month(and next year as well).
# Calculating previos month is pretty simple, send 'days=-1' to timedelta.
def nextmo(d, days=31):
"""Return today's next month. If want previous month, set 'days' to '-1'."""
mo = d.month
yr = d.year
nm = datetime.date(yr,mo,1)+datetime.timedelta(days=days)
return nm
if __name__ == "__main__":
dd = datetime.date(2000,1,31)
nm = nextmo(dd)
print "Next year: %s, next month: %s" % (nm.year, nm.month)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment