вы могли бы написать функцию, которая пробует несколько форматов для разбора строки:
from datetime import datetime
def parse_custom_date(s, formats=['%b %d %Y', '%b %d %y']):
dtobj = None
for f in formats:
try:
dtobj = datetime.strptime(s, f)
break # break loop if parse successful
except ValueError:
continue # invalid format, continue to next format in "formats"...
if dtobj:
return dtobj
# implicit else: function didn't return, so...
raise ValueError(f"no matching format found for '{s}' in {formats}!")
first_date, second_date = "May 2 2020", "Jun 30 20"
print((parse_custom_date(second_date)-parse_custom_date(first_date)).days)
# 59
first_date, second_date = "May 2 2020", "asdf"
print((parse_custom_date(second_date)-parse_custom_date(first_date)).days)
# ValueError: no matching format found for 'asdf' in ['%b %d %Y', '%b %d %y']!
[ref]