Date Formatting (No Time)

Jan 27, 2011 at 3:30 AM

I want a date without a time, just like you can manually format a cell in Excell.

I have read the FAQ about styles.

If I pass in a DateTime value, I always get a date and time in the completed spread sheet.

If I put it into a string in the format I want, it still adds the 12:00:00 AM time element.

Here are two of the various combinations that I have tried:

DateTime mydate = (DateTime)datagridview[col, row].Value;
worksheet.Cells[row + 2, col + 1].Style.Numberformat.Format = "mm/dd/yy";
worksheet.Cells[row + 2, col + 1].Value = mydate;


string mydate = string.Format("{0:MM/dd/yy}"), datagridview[col, row].value);
worksheet.Cells[row + 2, col + 1].Value = mydate;





If my DateTime value is 1/26/2011 2:31:25 PM and I test my string and it is "1/26/11" I still get 1/26/2011 12:00:00 AM in the cell.  If I use the DateTime method, I get the same thing that was in the source grid.

I would appreciate any ideas.




Jan 28, 2011 at 12:12 AM

Hi Dihaws,

Firstly, welcome to CodePlex.

Second, thank you for choosing EPPlus and posting your questions with us.

In hope to answer your question, please refer to this previous discussion.

Let me know if it is helpful.