Dates as Parameters to Custom Function not being evaluated to DateTime type.

Topics: Help
Nov 28, 2012 at 12:34 AM

Hi All

Firstly this is a great product.

I am having an issue with Dates specified as parameters and after evaluating they are the string value.  So my parameter is called P1 and before calling Evaluate() on the parameter the value is P1 after calling Evaluate() it is the parameter value as a string #21/11/2012# and then if I pass this into a new Expression() and call Evaluate() I get a DateTime out. Wondering if I am doing something wrong to get my date parameter evaluated as DateTime?

var e = new Expression("DatesSubtract(P1,#21/11/2000#)");
e.Parameters["P1"] = #22-11-2012#
e.EvaluateFunction+=delegate(string name, FunctionArgs args) {
 DateTime dt = (DateTime)args.Parameters[0].Evaluate();
=> Fails evaluated as #22-11-2012# and so cast to DateTime fails BUT
DateTime dt = (DateTime)(new Expression(args.Parameters[0].Evaluate().ToString()).Evaluate()); works but not expecting to have to do this??
}

Thanks

Dec 11, 2012 at 4:21 AM
expression.Parameters["P1"] = new Expression("#21/11/2000#").Evaluate(); 
I had to pass in the Parameters into a new expression instance (calling Evaluate() on the parameters was not enough) to make this work.