def strptime_musicbrainz(date_str):
 acceptable_formats = ('%Y-%m-%d', '%Y-%m', '%Y')
 for date_format in acceptable_formats:
  try:
   return datetime.datetime.strptime(date_str, date_format)
  except:
   pass
 return None

def strptime_musicbrainz ( date_str ) : acceptable_formats = ( '%Y-%m-%d' , '%Y-%m' , '%Y' ) for date_format in acceptable_formats : try : return datetime . datetime . strptime ( date_str , date_format ) except : pass return None
release date as returned by musicbrainz may contain the full date but it may as well be just year-month or even just the year .