Created
October 19, 2010 02:44
-
-
Save vvoody/633516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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