Using Excel with your formulas, I get 19, 49 and 0. So, there is a problem with the calculations in Essential Grid which we will correct.
The calculation seems to subtract an extra 30 days if the dates are in teh same month and year. If you want to add your own Days360 method until we public a corrected version, you can do so like this:
//in Form.Load, unhook the current library method
GridFormulaCellModel model = this.gridControl1.CellModels["FormulaCell"] as GridFormulaCellModel;
model.Engine.RemoveFunction("Days360".ToUpper());
//hook up your implementation
model.Engine.AddFunction("Days360", new GridFormulaEngine.LibraryFunction(ComputeDays360));
//Add the corrected method
public string ComputeDays360(string argList)
{
GridFormulaCellModel model = this.gridControl1.CellModels["FormulaCell"]
as GridFormulaCellModel;
string[] args = argList.Split(new char[]{'',''});
int argCount = args.GetLength(0);
if(argCount != 2 && argCount != 3)
{
return "wrong number of arguments";
}
double serialdate1;
double serialdate2;
bool method = false;
int days = 0;
if(double.TryParse(model.Engine.GetValueFromArg(args[0]), NumberStyles.Any, null, out serialdate1)
&& double.TryParse(model.Engine.GetValueFromArg(args[1]), NumberStyles.Any, null, out serialdate2)
&& (argCount == 2 || (method = (args[2] == "TRUE")))
)
{
DateTime dt1 = DateTime.FromOADate((int)serialdate1);
DateTime dt2 = DateTime.FromOADate((int)serialdate2);
bool flipSign = false;
if(dt2 < dt1)
{
flipSign = true;
DateTime t = dt1;
dt1 = dt2;
dt2 = t;
}
if(dt1.Day == 31)
dt1 = dt1.AddDays(-1);
if(dt2.Day == 31 && !method && dt1.Day < 30)
dt2 = dt2.AddDays(1);
else if (dt2.Day == 31)
dt2 = dt2.AddDays(-1);
if(dt2.Month == dt1.Month)
days = dt2.Day - dt1.Day;
else
days = 30 - dt1.Day + dt2.Day;
if(dt2.Year == dt1.Year && dt2.Month != dt1.Month)
days += 30 * (dt2.Month - dt1.Month - 1);
else if(dt2.Year != dt1.Year)
days += 30 * (12 - dt1.Month + dt2.Month - 1)
+ 360 * (dt2.Year - dt1.Year - 1);
if(flipSign)
days = -days;
}
else
return "Invalid Arguments";
return days.ToString();
}