1

I'm using this code to write a date on a cell

mWSheet1.Cells[row, 7] = "01/12/2019";

but when I open the Excel file, it saves "12/01/2019". How can I solve it?

  • Try to format the cell like this: `mWSheet1.Cells[row, 7].NumberFormat = "mm/dd/yyyy";` – dvo Sep 25 '19 at 19:55
  • Probably duplicated : https://stackoverflow.com/questions/3310800/how-to-make-correct-date-format-when-writing-data-to-excel – Oleg Sep 25 '19 at 19:59
  • 2
    I would not use ambiguous date formats - is that Jan 12th or Dec 1st? Use `DateTime.ToOADate()` to specify the date _value_ and let Excel worry about the formatting. – D Stanley Sep 25 '19 at 20:01

1 Answers1

0

have you tried passing your date using the Format class? Note that passing the ' in before the value will tell excel to format it as text and it shouldn't try and do its own formatting.

mWSheet1.Cells[row , 7] = "'" + Format("01/12/2019", "MM/dd/yyyy");
ag93
  • 343
  • 4
  • 17