Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-03-29
7
Medium Priority
?
277 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 1200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 800 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

604 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