title: How to correctly extract various Date formats from Text in Python
body: <p>I have to extract all the <strong>available dates from a PDF and then check among the dates which is Contract Date.</strong> </p>
  
  <p>For that first I want to extract all the Dates in the Text that i have extracted from PDF. Now the <strong>Dates can be in various formats</strong>. I have tried adding all flavours of dates in the below example. </p>
  
  <p>I tried using <strong>Datefinder Python module</strong> to extract all the dates. Although it comes close but throws <strong>few garbage dates initially and also doesn't match the first Date correctly</strong>. </p>
  
  <pre><code>import datefinder
  
  dateContent = """ Test
  I want to apply for leaves August,​ ​11,​ ​2017 I want to apply for leaves Aug, 23, 2017 I want to apply for leaves Aug, 21, 17 
  I want to apply for leaves August 20 2017
  I want to apply for leaves August 30th, 2017 I want to apply for leaves August 31st 17
  I want to apply for leaves 8/26/2017 I want to apply for leaves 8/27/17
  I want to apply for leaves 28/8/2017 I want to apply for leaves 29/8/17 I want to apply for leaves 30/08/17
  I want to apply for leaves 15 Jan 17 I want to apply for leaves 14 January 17
  I want to apply for leaves 13 Jan 2017
  I want to apply for leaves Jan 10 17 I want to apply for leaves Jan 11 2017 I want to apply for leaves January 12 2017
  """
  
  matches = datefinder.find_dates(dateContent)
  
  for match in matches:
      print(match)
  </code></pre>
  
  <p><strong>Response :</strong></p>
  
  <p>2019-08-05 00:00:00</p>
  
  <p>2019-06-11 00:00:00</p>
  
  <p>2017-06-05 00:00:00</p>
  
  <p>2017-08-23 00:00:00</p>
  
  <p>2017-08-21 00:00:00</p>
  
  <p>2017-08-20 00:00:00</p>
  
  <p>2017-08-30 00:00:00</p>
  
  <p>2017-08-31 00:00:00</p>
  
  <p>2017-08-26 00:00:00</p>
  
  <p>2017-08-27 00:00:00</p>
  
  <p>2017-08-28 00:00:00</p>
  
  <p>2017-08-29 00:00:00</p>
  
  <p>2017-08-30 00:00:00</p>
  
  <p>2017-01-15 00:00:00</p>
  
  <p>2017-01-14 00:00:00</p>
  
  <p>2017-01-13 00:00:00</p>
  
  <p>2017-01-10 00:00:00</p>
  
  <p>2017-01-11 00:00:00</p>
  
  <p>2017-01-12 00:00:00</p>
  
  <p><strong>As you can see, I have 17 such Date objects, but i am getting 19. Checking from bottom, last 16 match correctly. Then there is those initial Garbage.</strong>
  Once i get these Dates correctly, i can move forward with some kind of N-Gram model to check which Dates Context is to Contractual Information.</p>
  
  <p>Any help in resolving the issue would be great.</p>