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