Link to home
Start Free TrialLog in
Avatar of Rajar Ahmed
Rajar AhmedFlag for India

asked on

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

Avatar of Shinesh Premrajan
Shinesh Premrajan
Flag of India image


The problem is

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

however the function is named as


function addmont(months,date1)


Hope this helps


i mean you should call it as

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

and not

addmonth("6","23/05/2010");
Avatar of Rajar Ahmed

ASKER

by mistake i entered like dat here ,
it is not working anyway
Avatar of StealthyDev
StealthyDev

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

ASKER CERTIFIED SOLUTION
Avatar of StealthyDev
StealthyDev

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oopssssss