Solved

What is the function to add a number of days to a date?

Posted on 2007-03-29
7
261 Views
Last Modified: 2008-01-09
Hi Experts,

What is the function to add a number of days to a date?

I found this but I need it to add days:

<script>

var actDate = new Date() // now()

alert(addMonths(actDate, 3));


function addMonths(theDate, amtMonths){
  var xDate = new Date(theDate);
  return new Date(xDate.setMonth(xDate.getMonth()+(amtMonths*1)));
}

</script>

THANKS
0
Comment
Question by:indyng
  • 4
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
justinbillig earned 300 total points
ID: 18818479
you can do this

var dtmDate = new Date( )

dtmDate.setDate( dtmDate.getDate( ) + 3 )
0
 
LVL 1

Author Comment

by:indyng
ID: 18818615
justinbillig

Sorry one last quick question, how can I get the date to display as "dd/mm/yyyy" and also as "Sunday,March 3,2007"?

Thanks
0
 
LVL 8

Expert Comment

by:LocoTechCJ
ID: 18818760
formatDate(yourDateVariable, FormatString)  

where in your case, the FormatString would be "EE, MMM d,yyyy"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:indyng
ID: 18818765
I have this in the format I want but I don't know how to add days

   var d = new Date()

var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

colDate = weekday[d.getDay()] + " " + monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear()



   alert(colDate)

    }
   
0
 
LVL 8

Assisted Solution

by:LocoTechCJ
LocoTechCJ earned 200 total points
ID: 18818771
Oh that, was for displaying as "Sunday, March3,2007"

For "dd/mm/yyyy" use te format string "dd/MM/yyyy"
0
 
LVL 1

Author Comment

by:indyng
ID: 18818883

All I want is to modify the following script to add x number of days to the current date. How can I do this?



  function  InsertCollectDateToList(zonename)
   {
   
   var myarra1=array23;
   var zonename;

   var colDate;

   var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
   var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

   colDate = weekday[d.getDay()] + " " + monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear()

   alert(colDate)

   }
   
0
 
LVL 1

Author Comment

by:indyng
ID: 18818922
I now have this but it doesn't work

function AddDays(strDate,intDays){
      strDate = Date.parse(strDate);
      strDate = parseInt(strDate, 10);
      strDate = strDate + intDays*(24*60*60*1000);
      strDate = new Date(strDate);
}


  function  InsertCollectDateToList(zonename)
   {
   
   var myarra1=array23;
   var zonename;

   var d = new Date()

   var strDate ="<%=newformatDateTime(Date(),"M2/D2/Y2",0)%>"

   var colDate;



   var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
   var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")



   colDate = weekday[d.getDay()] + " " + monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear()

   alert(AddDays(strDate,1))

   }
   

Please help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now