Custom Search

Friday, March 26, 2010

How find future month and year in python

************************************

http://labix.org/python-dateutil#head-ba5ffd4df8111d1b83fc194b97ebecf837add454

today + relativedelta(months=1)


************************************

def next_month(self, date):
month = date.month+1
year = date.year
if month > 12:
month = 1
year = date.year+1
return datetime.datetime(year, month, 1)


************************************


today = datetime.date.today()
next_first_date = today + datetime.timedelta(today.day)
next_second_date = next_first_date + datetime.timedelta(today.day)
next_third_date = next_second_date + datetime.timedelta(today.day)
print "third", next_third_date
print "second", next_second_date
print "next_first_date", next_first_date

next_first_month = next_first_date.month
next_first_year = next_first_date.year
next_first_month_name = next_first_date.strftime("%b")

next_second_month = next_second_date.month
next_second_year = next_second_date.year
next_second_month_name = next_second_date.strftime("%b")

next_third_month = next_third_date.month
next_third_year = next_third_date.year
next_third_month_name = next_third_date.strftime("%b")

No comments:

Post a Comment