paul2463 Posted July 4, 2006 Share Posted July 4, 2006 HelloI 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 Quote Link to comment Share on other sites More sharing options...
nogray Posted July 5, 2006 Share Posted July 5, 2006 just replace this linesDate.setDate(sDate.getDate()+1);with thissDate.setDate(sDate.getDate()+count); Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 5, 2006 Author Share Posted July 5, 2006 Thanks will give that a goOK tried it but I get exactly the same result, I must admit that I dont understand how the origonal solution didnt work, but it didnt, anyone else got any ideas please Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 5, 2006 Author Share Posted July 5, 2006 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.