459,317 Members | 1,313 Online
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

# Weird IE6 Date Comparison bug

 P: 1 I'm creating a function that will take a start date, a period duration (in months)and a maximum date, and will calculate the periods start and end dates until reaching the maximum date. For instance, I would give 01/01/2008, period equals 3 months and maximum date equals 01/01/2009, and the method should return periods like "01/01/2008-03/31/2008","04/01/2008-06/30/2008","07/01/2008-09/30/2008","10/01/2008-12/31/2008". The code looks like: Expand|Select|Wrap|Line Numbers function getPeriods(p_startDate, p_duration, p_maxDate) {   var periodsList = [];   var nextStartDate, endDate, period, year, month, day;   var startDt = p_startDate;    do {     year = startDt.getUTCFullYear();     month = startDt.getUTCMonth();     day = startDt.getUTCDate();       nextStartDate = new Date();     nextStartDate.setFullYear(year, month + p_duration, day);       endDate = new Date(nextStartDate);     endDate.setDate(endDate.getDate()-1);       if(endDate >= p_maxDate) {       endDate = p_maxDate;     }     period = {"Start":startDt,"End":endDate};     periodsList[periodsList.length] = period;     startDt = nextStartDate;     //alert(periodsList.length);   }   while(p_maxDate > endDate);      return periodsList; }   function printPeriods(p_periodsList) {   alert(">>>" + p_periodsList.length);   //for(var i=0; i< p_periodsList.length ; i++)   //{     //alert("Start: " + p_periodsList[i].Start + "\nEnd: " + p_periodsList[i].End);   //} }   var st = new Date; st.setFullYear(2008,0,1); var max = new Date; max.setFullYear(2009,0,1); max.setDate(max.getDate()-1); printPeriods(getPeriods(st, 3, max)); However, when I run the code, the alert window will display ">>> 5" in IE6, while it displays ">>> 4" in Firefox, which is the expected length. To make things even stranger, if I uncomment the "alert" in the last line of the "do" block, IE will run the correct number of loops, displaying ">>> 4" in the end. Any ideas or workarounds? Thanks in advance! Sep 10 '08 #1