mickNeill
mickNeill

Reputation: 346

Python Openpyxl writing date to excel as short date

I am trying to write dates to an excel file using Openpyxl. I am using the following lines to write the date.

dttm = datetime.datetime.strptime(ls25Dict[cell.value][2], "%m/%d/%Y" )   
ws1['B'+ str(cell.row)].value = dttm

This writes the date to excel but in the wrong format. This is the output:

2018-01-09 0:00:00

I am trying to get it to be 1/9/2018. Basically change the format to Short Date in excel.

Anyone know how to change it before the date is written to excel?

Upvotes: 1

Views: 2937

Answers (1)

Charlie Clark
Charlie Clark

Reputation: 19507

In Excel you always have to provide your own format for dates and times, because these are stored as serials. openpyxl defaults to ISO formats for minimal ambiguity.

Upvotes: 1

Related Questions