0

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?

lily59
  • 1
  • 1

1 Answers1

0

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
Sekhar
  • 627
  • 4
  • 14
  • 34
  • i want a solution wrt datefinder becoz i have strings with more than one date. And if there are multiple dates in a string, parser function raises an Error. – lily59 May 23 '22 at 12:10