PDA

View Full Version : Need help calculating quarters....


Tanker
11-15-2002, 04:52 PM
I have an application that has quarterly reports. The users originally only wanted to see the quarters that were finished so I managed to scrape together some javascript that would give them that, they have now changed their minds and decided they would like to see the current quarter as well even though we don't have all the data.

Below is the current code we are using. After 2 days of tearing it apart I am still unable to make it show all end quarter dates from startDate including the end of the current quarter.

The list should look something like:
06/30/2002
09/30/2002
12/31/2002

If anyone can help it would be greatly appreciated.


function quarterly(){
var repPeriod = "Quarterly"
var startDate = ("05/04/2002");
var optArray = new Array();
var usrDate = new Date(startDate);
usrDate.setHours(12);
var curDate = new Date();
curDate = new Date(curDate.getFullYear(), curDate.getMonth(), curDate.getDate());
curDate.setHours(12)

var i = 0;
while (usrDate <= curDate) {
var myMonth = usrDate.getMonth() + 1;
getLastDay(usrDate)
if(myMonth <=9){myMonth = "0" + myMonth}
if(lastDay <=9){ myDay = "0" + lastDay}else{myDay = lastDay}

optArray[i] = myMonth + "/" + lastDay + "/" + usrDate.getYear();
document.write(myMonth + "/" + lastDay + "/" + usrDate.getYear() + "<br>");
usrDate.setMonth(usrDate.getMonth() + 3);
i++
}
optArray1 = optArray.reverse()
parent.makeStep6(repPeriod,optArray1)
}


function getLastDay(usrDate){
var tmpDate, d, m;
tmpDate = new Date(Date.parse(usrDate));
m = tmpDate.getMonth();
d = 28;
do {
d++;
tmpDate.setDate(d);
} while (tmpDate.getMonth() == m);
lastDay = d - 1;
return lastDay
}

Tanker
11-15-2002, 09:48 PM
After staring at it for awhile I went on to something else and came back, realized I was trying to retest the same variable I was changing if it passed the if statement. :(

Thanks. :)