I am using NCalc in a project. Is there a way to do date operations like
#16/02/2013# - #15/02/2013# = 1
I can't seem to be able to produce a result.
Expression.Evaluate();
Results is null for the above expression. I can compare two dates, but is there a way to do operations on them using NCalc?
You can do this in ncalc quite easily if you are happy to create a custom function.
Expression e = new Expression("DayDiff(#16/02/2013#, #15/02/2013#)");
e.EvaluateFunction += delegate(string name, FunctionArgs args)
{
if (name == "DayDiff")
{
var date1 = args.Parameters[0].Evaluate();
var date2 = args.Parameters[1].Evaluate();
var timespan = date2 - date1;
return timespan.TotalDays; // double (you can convert to int if you wish a whole number!)
}
}
Console.Write(e.Evaluate());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With