'datefinder.find_dates() is not able to extract date from a string when the date is followed by the terms "last", "until"
I was trying to extract date from strings using datefinder. I observed that datefinder.find_dates() is not able to extract date from a string when the date is followed by "last" ,"until"
text= "Created 2009.10.20last-modified"
list(datefinder.find_dates(text))
O/P : []
text= "Created 2009.10.20until-modified"
list(datefinder.find_dates(text))
O/P : []
text= "Created 2009.10.20registration"
list(datefinder.find_dates(text))
O/P : [datetime.datetime(2009, 10, 20, 0, 0)]
Are they reserved words in datefinder? Can someone please advise on how to handle such strings?
Solution 1:[1]
Parser will extract the date with '-'. You can use this.
from dateutil import parser
# initializing string
#test_str = "Created 2009.10.20last-modified"
test_str= "Created 2009.10.25until-modified"
# printing original string
print("The original string is : " + str(test_str))
# extracting date using inbuilt func.
res = parser.parse(test_str, fuzzy=True)
# printing result
print("Computed date : " + str(res)[:10])
Output:
The original string is : Created 2009.10.25until-modified
Computed date : 2009-10-25
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | raj S |
