devxlogo

Get the End Date of a Financial Quarter

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();}//-----------------------------------------
See also  How to Block Websites During Certain Hours on a Mac Computer
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist