Rajar Ahmed
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")
i mean you should call it as
addmont("6","23/05/2010");
and not
addmonth("6","23/05/2010") ;
addmont("6","23/05/2010");
and not
addmonth("6","23/05/2010")
ASKER
by mistake i entered like dat here ,
it is not working anyway
it is not working anyway
Hi. Actually instead of addition, string concatenation is happening..
Use this:
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oopssssss
The problem is
you caled it
addmonth("6","23/05/2010")
however the function is named as
function addmont(months,date1)
Hope this helps