import datetime aDate = datetime.date(2015, 1, 1) b = 0 if aDate <= datetime.date(2015,12,31): if (aDate.month + aDate.day) <= 12: b = b + 1 aDate = aDate + datetime.timedelta(days=1) print b