Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Oct 5, 2004

Get the End Date of a Financial Quarter

Often, in financial applications, the quarter end date is very important for financial calculations. The following function gets the end date of a Financial Quarter that is relative to the date value passed. For example, suppose you are passing "12-Apr-2004" as the Date. The corresponding quarter end date returned will be "30-Jun-2004."

public static Date getFinancialQuarterEndDate(Date date) {
	Calendar calendar = new GregorianCalendar();
	calendar.setTime(date);
	int factor = 0;
	int month = calendar.get(Calendar.MONTH);
	if (month == Calendar.JANUARY
		|| month == Calendar.APRIL
		|| month == Calendar.JULY
		|| month == Calendar.OCTOBER) {
		factor = 2;
	} else if (
		month == Calendar.FEBRUARY
		|| month == Calendar.MAY
		|| month == Calendar.AUGUST
		|| month == Calendar.NOVEMBER) {
		factor = 1;
		} else {
			factor = 0;
	}

	calendar.add(Calendar.MONTH, factor);
	calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
	return calendar.getTime();
}
//-----------------------------------------
Vijayanandraj Amaladoss
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap