We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DAYS360(startdate,EndData,method) function problem

Hi, I Try to use syncfusion DAYS360 function. I am not getting the correct result. My test scenarion is like below. case 1:- If I use DAYS360(DATEVALUE("10-Mar-2005"),TODAY()) . The result is -11 case 2:- If I use DAYS360(DATEVALUE("10-Feb-2005"),TODAY()).The result 49. case 3:- DAYS360(DATEVALUE("29-Mar-2005"),TODAY()). The result is -30. Can you help me to clarify this. MALLIK

4 Replies

AD Administrator Syncfusion Team March 29, 2005 06:56 AM

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();
}


AD Administrator Syncfusion Team March 29, 2005 07:49 AM

Here is new try at this 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")))
		)
	{
		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 < dt1)
		{
			flipSign = true;
			DateTime t = dt1;
			dt1 = dt2;
			dt2 = t;
		}
		days = dt2.Day - dt1.Day;
		days += 30 * (dt2.Month - dt1.Month);
		days += 360 * (dt2.Year - dt1.Year);
		if(flipSign)
			days = -days;
	} 
	else
		return "Invalid Arguments";

	
	return days.ToString();
}


MA mallikarjuna March 30, 2005 12:36 AM

Hi, Can I know when can we expect corrected version ? MALLIK. >Hi, > >I Try to use syncfusion DAYS360 function. I am not getting the correct result. >My test scenarion is like below. > >case 1:- >If I use >DAYS360(DATEVALUE("10-Mar-2005"),TODAY()) . The result is -11 > >case 2:- >If I use >DAYS360(DATEVALUE("10-Feb-2005"),TODAY()).The result 49. > >case 3:- >DAYS360(DATEVALUE("29-Mar-2005"),TODAY()). The result is -30. > >Can you help me to clarify this. > >MALLIK > > > > > > > >


AD Administrator Syncfusion Team March 30, 2005 03:32 AM

I do not know when a corrected version will be released. We are working on it now and a correction for this problem is in it. When this new version is available, it will be announced on our web site, and will be available for download for registered users from your Direct Trac support home page.

Loader.
Live Chat Icon For mobile
Up arrow icon