Solved

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

Posted on 2007-03-29
7
263 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
is this a cms? 8 60
ASP.NET gridview select textbox on focus 2 33
https://github.com/willowsystems/jSignature 11 46
Passport Expiry 3 44
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

785 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