Solved

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

Posted on 2007-03-29
7
259 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

705 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

16 Experts available now in Live!

Get 1:1 Help Now