change datetime format in python
<p>I am getting this datetime in this format from my database.</p>

<pre><code>2016-09-13T08:46:59.953948+00:00
</code></pre>

<p>I want to change this date into format like </p>

<pre><code>13 sep 2016 08:46:59
</code></pre>

<p>I have used datetime module like</p>

<pre><code>import datetime
datetime.datetime.strptime(2016-09-13T08:46:59.953948+00:00, 'changing format')
</code></pre>

<p>But it is giving error </p>

<pre><code>TypeError at /admin/help
must be string, not datetime.datetime
</code></pre>

<p>If you don't care about the timezone and milliseconds you can try by the following function:</p>

<pre><code>from datetime import datetime

def parse_db_time_string(time_string):
    date = datetime.strptime(time_string.split('.')[0], '%Y-%m-%dT%H:%M:%S')
    return datetime.strftime(date, '%d %b %Y %H:%M:%S')
</code></pre>

<p>You can call the function with your db strings then simply like this:</p>

<pre><code>old_time_string = '2016-09-13T08:46:59.953948+00:00'
new_time_string = parse_db_time_string(old_time_string)
</code></pre>

python django