title: Convert date format yyyy-m-d into yyyy-mm-dd on Python
body: <p>In my table, I have different types of dates just with numbers and in this two formats:</p>
  
  <pre><code>yyyy-m-d
  yyyy-mm-dd
  </code></pre>
  
  <p>Some values, as the month for example, don't have the zero in the case of months under 10 and I need it to create a condition to chose elements by the latest date.</p>
  
  <p>I want that all of them have the same format:</p>
  
  <pre><code>yyyy-mm-dd
  </code></pre>
  
  <p>Any pythonic way to solve that?</p>
  
  <p>For the moment I am using this:                 </p>
  
  <pre><code>if line.startswith('# Date:           '):
      #date = 2014-5-28
      d = line.strip().split(':')[-1].split('-').replace(' ','') 
          if len(d[0]) == 4:
              year = str(d[0])
          elif len(d[1]) &lt; 2:
              month = '0'+ str(d[1])
          elif len(d[2]&lt; 2):
              day = '0'+ str(d[1])
  
                          date = year +  month + day 
  </code></pre>