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 1721
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...
|
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...
|
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...
|
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....
|
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...
|
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,
...
|
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...
|
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...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |