Jump to content

Date Problem


paul2463

Recommended Posts

Hello

I am struggling with something to do with dates and placing them in an array, for information in the script the sy,sm,sd,ey,em,es are all configured and sDate and eDate are correctly configured dates. All I have is a start date and an end date I need to fill all the rest of the dates in as well ( ie sDate = 04 July 2006 and eDate = 07 July 2006, i need to also add the 5th and 6th)
[code]

var sDate = new Date(sy,sm,sd);
var eDate = new Date(ey,em,ed);
var dates = new Array();
var count = 0;

while (sDate <= eDate)  {
    dates[count] = sDate;
    sDate.setDate(sDate.getDate()+1);
    count ++;
}[/code]

what happens is that I get an array of dates for correct number of days that is should be, but all dates are the same and they are all eDate+1, so for the above example before the code I get an array of length 4 but all slots have 8 July 2006 in it. I am all confused
Link to comment
Share on other sites

I have even now changed it for a FOR loop, I have claculated the number of days difference between the start date and end date and use that in the loop, here is the code
[code]
var sDate = new Date(sy,sm,sd);
  var eDate = new Date(ey,em,ed);
  var dates = new Array();
  var num = (eDate - sDate)/86400000;
for (i=0 ; i<=num ; i++) {
      dates[i] = sDate;
      sDate.setDate(sDate.getDate()+1);
      }[/code]

I still get an array object that is the correct length but it is filled with the same date again, the day after the end date, crazy eh? why isnt it doing what I ask, which is to place sDate into slot i then add a day onto it then place the new sDate into the next slot?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.