473,606 Members | 2,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird IE6 Date Comparison bug

1 New Member
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
  1. function getPeriods(p_startDate, p_duration, p_maxDate)
  2. {
  3.   var periodsList = [];
  4.   var nextStartDate, endDate, period, year, month, day;
  5.   var startDt = p_startDate; 
  6.   do {
  7.     year = startDt.getUTCFullYear();
  8.     month = startDt.getUTCMonth();
  9.     day = startDt.getUTCDate();
  10.  
  11.     nextStartDate = new Date();
  12.     nextStartDate.setFullYear(year, month + p_duration, day);
  13.  
  14.     endDate = new Date(nextStartDate);
  15.     endDate.setDate(endDate.getDate()-1);
  16.  
  17.     if(endDate >= p_maxDate) {
  18.       endDate = p_maxDate;
  19.     }
  20.     period = {"Start":startDt,"End":endDate};
  21.     periodsList[periodsList.length] = period;
  22.     startDt = nextStartDate;
  23.     //alert(periodsList.length);
  24.   }
  25.   while(p_maxDate > endDate); 
  26.  
  27.   return periodsList;
  28. }
  29.  
  30. function printPeriods(p_periodsList)
  31. {
  32.   alert(">>>" + p_periodsList.length);
  33.   //for(var i=0; i< p_periodsList.length ; i++)
  34.   //{
  35.     //alert("Start: " + p_periodsList[i].Start + "\nEnd: " + p_periodsList[i].End);
  36.   //}
  37. }
  38.  
  39. var st = new Date;
  40. st.setFullYear(2008,0,1);
  41. var max = new Date;
  42. max.setFullYear(2009,0,1);
  43. max.setDate(max.getDate()-1);
  44. 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
1 1731
acoder
16,027 Recognized Expert Moderator MVP
Weird indeed. This also occurs in IE7. Since it works with the alert, there must be some timing bug. It may work if you use a small timeout.
Sep 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
13111
by: Donnal Walter | last post by:
I was very surprised to discover that >>> import datetime >>> x = datetime.date(2004, 9, 14) >>> y = datetime.datetime(2004, 9, 14, 6, 43, 15) >>> print x == y True How can these two objects be considered equal? Is there a *general* way to test for date != datetime as well as 4.5 != 4.6?
2
10202
by: Scott Knapp | last post by:
Good Day - I have a form which sets the current date, as follows: <script type="text/javascript"> xx=new Date() dd=xx.getDate() mm=xx.getMonth()+1 yy=xx.getYear() mmddyy=mm+"/"+dd+"/"+yy document.write(mmddyy)
3
6557
by: Karl Gibbon | last post by:
Hi There, I currently have a database in Access 2002 with several forms. I would like to restrict access to one form in perticular until November 1st every year. My current method (attempted method) is a heavy handed, no nonsense, direct date comparison using VBA. Function NovemberOnwards() 'Use with 'On Avtivate' on Orders form CurrentDate = Date 'I cannot decide which function is best to use
6
8486
by: MarkAurit | last post by:
Im having difficulty coming up with a good algorithm to express the following comparison: "if <a given date> falls between the (current date - 5 days) and the (current date)" Obviously. DateTime.Now and something like (AddDays(DateTime.Now,-5) are used for the inner and outer ranges, its how to express the "between" that has me. /* what Id like to do, in pseudo code */ dateToTest=DateTime.Parse("mm/dd/yy");
3
10220
by: Tiya | last post by:
Hi there !!! I would like to know how to compare dates in javascript. var sdate = new Date(theform.SubmissionDate.value); var odate = new Date(theform.StartDate.value); var todaysdate = new Date(); if(sdate < todaysdate)
4
3746
by: blini | last post by:
Helo.... How I can convert string "26/03/2006 15:51" for a date? I need to convert and to compare if "09/06/2006 14:20" is lesser or equal that the current date. Everything in Javascript.
7
2764
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, here is my table structure, Name: Table1
5
1665
by: Anja | last post by:
Hi everyone, I want to write a simple SQL statement that does a comparison on a date field. For a simple test, I have the following SQL Statement: SELECT * FROM Records_T where TransactionDate =#12/09/2006# I have a record that fulfills the criterion but this query returns
4
7402
by: anagai | last post by:
I just want to check if a date entered in a textbox is equal to the current system date. I set the date object from the input field like this: dt1=new Date('10/01/2007'); the current system date is retrieved like this: curDt = new Date();
0
7962
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8315
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6792
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5467
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3945
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1309
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.