I want to add +1 if the date is sunday. Below code works for the rest dates. But when I pass 30 sept 2012 I gives me 1 Sept 2012 instead of 1 Oct 2012 in dateMsg. What is wrong with the code?. Please guide. I guess I'l face same problem in all last date of the month.How to add 1 to whole date rather than just the day?
var monthName=convertMnthNoToName(freeLookEndDt.getMonth()+1);
if (freeLookEndDt.getDay()==0) {
var date=new Date(freeLookEndDt.getFullYear(),freeLookEndDt.getMonth(),
freeLookEndDt.getDate()+1);
var newmonthName=convertMnthNoToName(date.getMonth()+1);
var dateMsg = date.getDate() + '-' + monthName + '-' + freeLookEndDt.getFullYear();
document.forms[0].flEndDt.value=dateMsg;
}
and convertMnthNoToName()
function convertMnthNoToName(val)
{
if(val==01 || val==1)
{
val1="Jan";
}
if(val==02 || val==2)
{
val1="Feb";
}
if(val==03 || val==3)
{
val1="Mar";
}
if(val==04 || val==4)
{
val1="Apr";
}
if(val==05 || val==5)
{
val1="May";
}
if(val==06 || val==6)
{
val1="Jun";
}
if(val==07 || val==7)
{
val1="Jul";
}
if(val==08 || val==8)
{
val1="Aug";
}
if(val==09 || val==9)
{
val1="Sep";
}
if(val==10)
{
val1="Oct";
}
if(val==11)
{
val1="Nov";
}
if(val==12)
{
val1="Dec";
}
return val1;
}
where freeLookEndDt = Sun Sep 30 00:00:00 UTC+0530 2012
convertMnthNoToNamefunction in 3 lines gist.github.com/3890921var d = new Date(2012,8,30); b = new Date( 2012,8, d.getDate() + 1); b;works fine for me, perhaps something is wrong with yourfreeLookEndDtobject