add month is not working properly in javascript

i need to add month , but the below script not working properly .
function addmont(months,date1){

arry=date1
var ArrDoj=arry.split("/");	       	       
	                var myDate = new Date(ArrDoj[2],ArrDoj[1],ArrDoj[0]);
                    ////add a month
                    myDate.setMonth(myDate.getMonth() + months);
                    var strday=myDate.getDate();//.getDay();
                    var strMonth=myDate.getMonth();
                    //var strmonthchange=DateChange(strMonth);
                    var strYear=myDate.getFullYear();
                   var enddate=strday + "/" + strMonth + "/" + strYear;
                   alert(enddate)
}
addmonth("6","23/05/2010")

Open in new window

LVL 18
Rajar AhmedConsultantAsked:
Who is Participating?
 
StealthyDevCommented:
In the previous post I have converted:

addmonth("6", "23/05/2010") => means months = "6" to months = 6
(string to int) by months = months - 0

You dont have to do it if you use:

addmonth(6, "23/05/2010") => without double quotes (int)

Means, your code is correct, you are passing string instead of int :)

Best Regards.

0
 
Shinesh PremrajanEngineering ManagerCommented:

The problem is

you caled it
addmonth("6","23/05/2010")

however the function is named as


function addmont(months,date1)


Hope this helps


0
 
Shinesh PremrajanEngineering ManagerCommented:
i mean you should call it as

addmont("6","23/05/2010");

and not

addmonth("6","23/05/2010");
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Rajar AhmedConsultantAuthor Commented:
by mistake i entered like dat here ,
it is not working anyway
0
 
StealthyDevCommented:
Hi. Actually instead of addition, string concatenation is happening..

Use this:


<script>
function addmonth(months,date1)
{
	arry=date1
	var ArrDoj=arry.split("/");	       	       
	var myDate = new Date(ArrDoj[2],ArrDoj[1],ArrDoj[0]);
	////add a month
	months = months - 0;
	myDate.setMonth(myDate.getMonth() + months);
	var strday=myDate.getDate();//.getDay();
	var strMonth=myDate.getMonth();
	//var strmonthchange=DateChange(strMonth);
	var strYear=myDate.getFullYear();
	var enddate=strday + "/" + strMonth + "/" + strYear;
	alert(enddate)
}
addmonth("6","23/05/2010")
</script>

Open in new window

0
 
Rajar AhmedConsultantAuthor Commented:
oopssssss
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.