2

I was having a problem with dateparser when it is given a string such as "Dec. 3-4". I have an array of dates (without year) but I have no idea how I would split up that date to make it print out "12/3" and "12/4".

My current output is "12/3" and then it gives me an error NoneType' object has no attribute 'strftime'. Here is the for loop I am using to print out the dates.

for i in range(len(data_table)):
    date = dateparser.parse(data_table[i][0])
    date_output.insert(i, date.strftime("%m/%d/2020"))
    txt_two = "{:25}{}".format(date_output[i], data_table[i][1])
    print(txt_two)
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

1

For ranges I came up with something like this:

def extract_dates(date_string):
  matcher = matcher = re.compile('\\d+-\\d+')
  match = matcher.search(date_string)
  if match:
    start, end = match.group(0).split('-')
    prefix = date_string[:5]
    return [prefix + str(i) for i in range(start, end + 1)]
  else:
    return [date_string]
szatkus
  • 1,292
  • 6
  • 14