Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thangarajan8/7b3016ec9fc5c44b1bfec90851808049 to your computer and use it in GitHub Desktop.
Save thangarajan8/7b3016ec9fc5c44b1bfec90851808049 to your computer and use it in GitHub Desktop.
multi_date_text.py
import datetime
# text = "april 23 january 11 2020"
text = "enero 01 diciembre 31 2020"
def multi_date_text(text):
month_dict = {"enero":"january","febrero":"february","marzo":"march","abril":"april",
"mayo":"may","junio":"june","julio":"july","agosto":"august",
"septiembre":"september","octubre":"october","noviembre":"november","diciembre":"december"}
text = [month_dict[i] if i.lower() in month_dict.keys() else i for i in text.split(" ") ]
date1_text = ' '.join(text[:2])+' '+text[-1]+' 00:00:00'
date2_text = ' '.join(text[2:4])+' '+text[-1]+' 00:00:00'
date1 = datetime.datetime.strptime(date1_text, '%B %d %Y %H:%M:%S')
date2 = datetime.datetime.strptime(date2_text, '%B %d %Y %H:%M:%S')
return date1, date2
print(multi_date_text(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment