import datetime start_str = '2015-01-01 0:0:0' end_str = '2015-12-31 0:0:0' start_tdatetime = datetime.datetime.strptime(start_str, '%Y-%m-%d %H:%M:%S') start_tdate = datetime.date(start_tdatetime.year, start_tdatetime.month, start_tdatetime.day) end_tdatetime = datetime.datetime.strptime(end_str, '%Y-%m-%d %H:%M:%S') end_tdate = datetime.date(end_tdatetime.year, end_tdatetime.month, end_tdatetime.day) # print(start_tdate) # print(end_tdate) count = 0 for i in range((end_tdate - start_tdate).days + 1): date = start_tdate + datetime.timedelta(days=i) if(date.month == date.day % 10 + date.day // 10): # print(date) count += 1 print(count)