title: How to convert different formats of date into one format using python
body: <p>Input: A date field that includes date in various formats (including: <code>yyyy/dd/mm</code>, <code>dd-mm-yyyy</code>, etc.), for example:</p>
  
  <pre><code>2017/5/23
  22-04-2015
  20150504
  </code></pre>
  
  <p>Output: date field in a uniform format. All date values should be converted to the <code>yyyymmdd</code> format. i.e. above input should generate output as:</p>
  
  <pre><code>20170523
  20150422
  20150504
  </code></pre>
  
  <p>I tried using <code>dateutils</code> but the output format is 2015-05-23</p>
  
  <pre><code>from datetime import datetime
  INPUT_FILENAME = 'date.txt'
  OUTPUT_FILENAME = 'newfile.txt'
  INPUT_DATE_FORMATS = {'column1dt': '%Y%m%d', 'column1dt': '%d/%m/%Y'}
  OUTPUT_DATE_FORMAT = '%Y%m%d'
  with open(INPUT_FILENAME, 'rt') as finput:
  reader = finput.readlines()
  with open(OUTPUT_FILENAME, 'wt') as foutput:
      print foutput 
      for row in reader: 
  </code></pre>