How to convert a python datetime.datetime to excel serial date number

前端 未结 6 1207
孤街浪徒
孤街浪徒 2020-11-27 16:01

I need to convert dates into Excel serial numbers for a data munging script I am writing. By playing with dates in my OpenOffice Calc workbook, I was able to deduce that \'1

6条回答
  •  时光取名叫无心
    2020-11-27 16:42

    While this is not exactly relevant to the excel serial date format, this was the top hit for exporting python date time to Excel. What I have found particularly useful and simple is to just export using strftime.

    import datetime
    current_datetime = datetime.datetime.now()
    current_datetime.strftime('%x %X')
    

    This will output in the following format '06/25/14 09:59:29' which is accepted by Excel as a valid date/time and allows for sorting in Excel.

提交回复
热议问题