Share via

Microsoft excel functions returns a wrong result

Yamen Jeribi 41 Reputation points
2021-08-16T14:05:47.153+00:00

Hi All,

I use this dll "Microsoft.Office.Interop.Excel" in order to evaluate my excel functions.

 public dynamic EvaluteFormula(string expressionFormula)
     {
         Application excelApp = new Application();
         return excelApp.Evaluate(expressionFormula);
     }

When I use TODAY/NOW function, I don't get the expected result instead I get a number, for example the result of :

  • TODAY() is 44424.
  • NOW() is 44424.613976967594

Has anyone ideas how to solve this problem ?

I encountered this problem with date related functions, I don't know if this issues applies on other functions.

Thanks!

Microsoft 365 and Office | Excel | For business | Windows
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2021-08-16T17:10:52.117+00:00

Use a specially designed function — FromOADate:

double example = 44424.613976967594;
DateTime date = DateTime.FromOADate( example );

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Paul 25 Reputation points
    2024-12-19T18:25:33.39+00:00

    you can force the date formatting by adding a text command that specifies the required formatting try using

    =TEXT(TODAY(),"DDD DD MMM YYYY")

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Castorix31 91,876 Reputation points
    2021-08-16T15:04:17.32+00:00

    Dates in Excel are from 1899

    Test :

                    var nResult = EvaluteFormula("TODAY()");
                    DateTime dt = new DateTime(1899, 12, 30);
                    DateTime dtToday = dt.AddDays(nResult);
    

    and I get :

    dtToday = {16/08/2021 00:00:00}

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.