Convert full month and day name to short ones
<p>I have a series of dates of this format: <code>'2015 08 01'</code> or <code>'2015 12 11'</code> and I want to convert them to this format: <code>'2015 8 1'</code> or <code>'2015 12 11'</code>. Basically, if the month and day sub-strings have a 0 at the start, that should be eliminated.</p>

<p>For example: The <code>'2015 08 01'</code> date string of the format (<code>"%Y %m %d"</code>), has the month number as <strong>08</strong> and day number as <strong>01</strong>. I want the resulting date to be:  <code>'2015 8 1'</code>, where the month is converted from <strong>08</strong> to <strong>8</strong> and the day from <strong>01</strong> to <strong>1</strong>.</p>

<p>I tried:</p>

<pre><code>from datetime import datetime
str_date = '2015 08 01'
data_conv = datetime.strptime(str_date, "%Y%m%e")
</code></pre>

<p>but I get this error:</p>

<pre><code>ValueError: 'e' is a bad directive in format '%Y%m%e'
</code></pre>

<p>Just remove the leading zeroes:</p>

<pre><code>' '.join([x.lstrip('0') for x in str_date.split()])
</code></pre>

python datetime