Fix Xl(sx|wt)Writer always using date_format even if a datetime is supplied. by filmor · Pull Request #7075 · pandas-dev/pandas (original) (raw)
In the XlsxWriter and XlwtWriter implementations there is a minor bug resulting in the datetime_format being discarded (i.e. https://github.com/pydata/pandas/blob/master/pandas/io/excel.py#L662):
if isinstance(cell.val, datetime.datetime):
num_format_str = self.datetime_format
if isinstance(cell.val, datetime.date):
num_format_str = self.date_format
Since datetime.datetime derives from datetime.date the second if-clause in the will always trigger, leading to the num_format_str being overwritten by the date_format.