DateRecognition is a Pure-Python library for extracting dates from strings.
python3.6+
Use the package manager pip to install DateRecognition.
pip install daterecognition
from daterecognition.parser import CoreDateParser as Parser
import daterecognition.formats as FORMATS
dp = Parser(formats=FORMATS.USA, start_year=2015, end_year=2020)
# or provide list of date formats in 1989 C Standard
dp = Parser(formats=[r"%B %-d, %Y"], start_year=2015, end_year=2020)
query = "Today is April 1, 2020"
dates = dp.parse_string(query)
print(dates)
[
{
'string': 'april 1, 2020',
'char_start_idx': 9,
'char_end_idx': 21,
'date_format': '%B %-d, %Y',
'token_start_idx': 2,
'token_end_idx': 4
}
]
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.