This simple code will give you the quarter to which the provided date belong to. We need to provide the FY Start date too.
public String getQuarter(Date date){
int monthNo = date.getMonth();
int year = date.getYear();
int temp = year - 100;
String quarterInfo = null;
int fyStart = getFyStart(); //4 if fyStarts in April
if (monthNo < fyStart) {
monthNo = 12 + monthNo;
} else {
temp = temp + 1;
}
int q1End = fyStart + 3;
int q2End = q1End + 3;
int q3End = q2End + 3;
int q4End = q3End + 3;
if (monthNo >= fyStart && monthNo < q1End) {
quarterInfo = "Q1" + " \'" + temp;
} else if (monthNo >= q1End && monthNo < q2End) {
quarterInfo = "Q2" + " \'" + temp;
} else if (monthNo >= q2End && monthNo < q3End) {
quarterInfo = "Q3" + " \'" + temp;
} else if (monthNo >= q3End && monthNo < q4End) {
quarterInfo = "Q4" + " \'" + temp;
} else {
quarterInfo = "None";
}
return quarterInfo;
}
Hope this helps
No comments:
Post a Comment