Search code examples
exceldatetimeexcellibrary

DateTime is rounded up to the next day using ExcelLibrary


The datetime I'm writing to Excel always get rounded up to the next day:

workSheet.Cells[0, 0] = new Cell(DateTime.Now, new CellFormat(CellFormatType.DateTime, @"HH:mm:ss"));

In the output Excel file the cell gets this value: 29/09/2013 00:00:00

The DateTime.Now from this example is 28/09/2013 19:42:23


Solution

  • I ended up passing the cell value as a string instead of as a DateTime:

     workSheet.Cells[0, 0] = new Cell(DateTime.Now.ToString(@"HH:mm:ss:ff"),
                                      new CellFormat(CellFormatType.DateTime, @"HH:mm:ss"));