Guest cfican Posted October 17, 2006 Share Posted October 17, 2006 How do I add a number of days > 30 to a specified date? Code here retrieves the number of days from a target date (seedDay) and I want to add that value (daysSince) to the seed day. (it is calculating the start and end dates of two week time periods given any date in between) var seedDay = new Date(2006,8,23);var aDay = 24*60*60*1000;var today = new Date();seedTime = seedDay.getTime();presentTime = today.getTime();daysSince = presentTime - seedTime;daysSince = Math.ceil(daysSince/aDay);bequith = (daysSince/14); // the goal here is to get an end date notbequith = Math.ceil(bequith); // this is getting the number of days from the while (bequith < notbequith) { // start date to the date I want daysSince = daysSince + 1; // it works, I want to add this number to a date object bequith = (daysSince/14); notbequith = Math.ceil(bequith); }// daysSince this comming pay period is 28 days since the seedDay, so . . .seedDay.getDay() + daysSince; // <-- this does not work Thankscfican Link to comment Share on other sites More sharing options...
jesh Posted October 17, 2006 Share Posted October 17, 2006 http://www.w3schools.com/js/js_obj_date.aspAnd in the following example we set a Date object to be 5 days into the future:var myDate=new Date()myDate.setDate(myDate.getDate()+5) Note: If adding five days to a date shifts the month or year, the changes are handled automatically by the Date object itself! I think if you change the last line of your code to something like the following it should work:seedDay.setDate(seedDay.getDate() + daysSince); Link to comment Share on other sites More sharing options...
jhecht Posted October 18, 2006 Share Posted October 18, 2006 use quotes around this: //var seedDay = new Date(2006,8,23);//This should bevar seedDay = new Date("08/23/2006 00:00:00"); Also you could juse compare the UNIX timestamp from the seeded day and the current day, and then just divide by 100 multiplied by 60*60*24(60 seconds multiplied by 60 minutes in one hour multiplied by 24 hours in one day), which would give you how many days until the next day, or FROM the next day(you may have to doa check if the returned value is negative and accomadate the text for that)If you want i can show you a real quick script for it. Link to comment Share on other sites More sharing options...
Guest cfican Posted October 18, 2006 Share Posted October 18, 2006 http://www.w3schools.com/js/js_obj_date.aspI think if you change the last line of your code to something like the following it should work:seedDay.setDate(seedDay.getDate() + daysSince); Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now