import datetime day = datetime.datetime.strptime("2015-1-1","%Y-%m-%d") count = 0 for i in range(365): allday = allday + datetime.timedelta(days=1) month = allday.month day = allday.day if month == int(day / 10) + day % 10: count += 1 print(count)