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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DAYS360(startdate,EndData,method) function problem

Thread ID:

Created:

Updated:

Platform:

Replies:

26639 Mar 29,2005 10:01 AM UTC Mar 30,2005 08:32 AM UTC Windows Forms 4
loading
Tags: GridControl
mallikarjuna
Asked On March 29, 2005 10:01 AM UTC

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

Administrator [Syncfusion]
Replied On March 29, 2005 11:56 AM UTC

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

Administrator [Syncfusion]
Replied On March 29, 2005 12:49 PM UTC

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

mallikarjuna
Replied On March 30, 2005 05:36 AM UTC

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 > > > > > > > >

Administrator [Syncfusion]
Replied On March 30, 2005 08:32 AM UTC

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;