Xlxswriter - Change Date format from str to date
<p>I am having trouble changing the date format of date column in the dataframe i created using Xlsxwriter. The current format is 3/31/2016  12:00:00 AM, which i thought python is reading a date and adding a time to it. I would like the format to simply be dd/mm/yyyy with know time associate with it for all of column A. </p>

<p>Here is my code:</p>

<pre><code>date_format= workbook.add_format({'num_format': 'mmm d yyyy'})
date_time= dt.datetime.strftime("%m/%d/%Y")
worksheet.write_datetime(0,0, date_time, date_format)
</code></pre>

<p>The error message i get is : TypeError: descriptor 'strftime' requires a 'datetime.date' object but received a 'str'</p>

<h2><code>datetime.strftime</code> is for converting datetimes into strings</h2>

<p>You are not giving it a datetime object to convert.</p>

<pre><code>from datetime import datetime
today = datetime.today()   # this returns a datetime object
today.strftime("%m/%d/%Y") # this returns a string
datetime.strftime(today, "%m/%d/%Y") # alternative way to call it
</code></pre>

<h2>However, you actually need to pass a datetime object to <code>worksheet.write_datetime</code></h2>

<p>So in my example it would be like this</p>

<pre><code>today = datetime.today()
date_format= workbook.add_format({'num_format': 'mmm d yyyy'})
worksheet.write_datetime(0, 0, today, date_format)
</code></pre>

<h2>To parse a date from a string use date time.strptime</h2>

<pre><code>dateobj = date time.strptime(datestr)
</code></pre>

python datetime xlsxwriter