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: - 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!
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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?
|
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)
|
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
|
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");
|
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)
| |
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.
|
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
|
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
|
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();
|
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,...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |