Get the end date of last quarter

date, java

Solution

Basically:

- Figure out which is the current quarter

- Return the last date of the previous quarter (March 31, June 30, September 30, December 31)

So to figure out which is the current quarter: `int quarter = (myDate.getMonth() / 3) + 1;` (Note that getMonth() is deprecated in favor of `Calendar.get(Calendar.MONTH)`.)

Then match the previous quarter to a date.

int prevQuarter = (myDate.getMonth() / 3); 
switch(prevQuarter) {
    case 3 : 
        // return September 30
    case 2 :
        // return June 30
    case 1 :
        // return March 31
    case 0 : default :
        // return December 31
}

Problem

For a given date, how to get the end date of last quarter? I need to run a job, which takes this into account. EDIT: 1st quarter is Jan, Feb, Mar; 2nd is Apr, May, June, so on; Any help is appreciated. Thanks

Original source