Solved

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

Posted on 2007-03-29
7
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Duplicate Elements with JS / jQuery 3 24
Can anyone help me find this preloader? 51 42
REST call Failing 1 11
Boolean 13 22
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

749 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