Creating a date from a previous date and adding to it

Hi I have a variable called myDate and it is set properly. If you care to see here is how I did it...

var myDate=new Date();
var ev_num = parseInt(document.getElementById("leave").value)
myDate.setFullYear(sel_year.value,sel_month.value,sel_day.value);

I have another variable called first_number. I am trying to set it to myDate and simply add 31 days to it, but the date being displayed is incorrect. Here is my code for it. Can someone please help me fix it...

    var first_number = new Date();
    first_number.setDate(myDate.getDate() + 31);

Answers


I think you want to initialize first_number with the myDate, instead of creating a new (current) Date object. To do so, use

var first_number = new Date(myDate);

Need Your Help

XML Schema not working with Web Service Software Factory

c# wcf xsd service-factory

I am trying to create an XML schema to use with the Web Service Software Factory. It's a fairly simple schema that is just a group of person objects. The (simplified) schema file looks like:

Beer Ranking Tournament

machine-learning statistics ranking bayesian

I would like to invite a number of friends over for a beer ranking tournament. Every attendee will be asked to bring a 'bomber' (1 pint) of the best beer they can find. Let F be a vector of friends...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.