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