0

How can I get the exact format date in Excel?

I need to create an Excel sheet from some data (in my "models.py" date_result_stamp it's DateTime field) in Django project and I don't know how I can pass the exact date (not str or another type of data) into Excel.

result["date_result_stamp"] = datetime.strftime(result["date_result_stamp"], "%Y-%m-%d")

It's str format and I need to get the date format.

Can you help me?

Witherfield
  • 135
  • 1
  • 1
  • 13
Flower
  • 23
  • 6
  • https://stackoverflow.com/questions/9574793/how-to-convert-a-python-datetime-datetime-to-excel-serial-date-number/24410858 Does this work for you? – C Puneeth Nov 16 '21 at 15:43
  • If your using xlrd you could use their xldate_from_datetime_tuple function https://xlrd.readthedocs.io/en/latest/api.html#xlrd.xldate.xldate_from_datetime_tuple – Jimmy Pells Nov 16 '21 at 15:55
  • Jimmy Pells, I use xlsxwriter – Flower Nov 16 '21 at 16:02
  • Maybe https://xlsxwriter.readthedocs.io/working_with_dates_and_time.html will help looks like `worksheet.write_datetime(row, col, datetime.strftime(result["date_result_stamp"], "%Y-%m-%d"))` – Jimmy Pells Nov 16 '21 at 18:46

0 Answers0