Created
April 26, 2022 08:20
-
-
Save thangarajan8/7b3016ec9fc5c44b1bfec90851808049 to your computer and use it in GitHub Desktop.
multi_date_text.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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