Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
260
Date math fail
posted

Hi,

I'm having a problem getting the excel component to do some simple date math. If I apply the following formula:

wb.Worksheets[

"X"].Rows[0].Cells[0].CellFormat.FormatString = "m/d/yy";
wb.Worksheets[

 

"X"].Rows[0].Cells[0].CellFormat.FormatString = "m/d/yy";
wb.Worksheets[

"X"].Rows[0].Cells[0].CellFormat.FormatString = "m/d/yy";
wb.Worksheets[

 

"X"].Rows[0].Cells[0].ApplyFormula("=1/1/2010 + 10");

I'm expecting what Excel would give me: "1/11/2010", instead, I get the following answer:

10.0004975124378

Any tips?

Parents
No Data
Reply
  • 8421
    Suggested Answer
    posted

    A better approach would be to use the formula "=DATE(2010,1,1) + 10". Testing this formula in Excel I get the expected result.

    The formula that you are applying is a numerical formula and returns a numerical answer rather than a date answer. If I test that formula in Excel without setting a format string then I get the same answer, 10.0005. If I do set the format string so that the cell is a date then I get 1/10/1900.

Children
No Data