Google spreadsheet function

function endofmonth(input) {

var daysDays0 = 28;
var daysDays1 = 29;
var daysDays2 = 30;
var daysDays3 = 31;



 
var str = "11-12-1959";
var res = str.split(" ");

//prompt("str");
//alert("str");


dDate = res[0];
mMonth = res[1];
yYear = res[2] + 60;

mathsdDate = dDate;
mathsmMonth = mMonth;
mathsyYear = yYear;

leapyearornot = "no"

leapyear = mathsyYear % 400;

if (leapyear == 0) {
 leapyearornot = "yes"
} else { 
 leapyear = mathsyYear % 100
}


if (leapyear == 0) {
 leapyearornot = "yes"
} else { 
 leapyear = mathsyYear % 4
}

if (leapyear == 0) {
 leapyearornot = "yes"
} else { 
// 
}


if (mathsdDate == 1) {
 lastmonthornot = "yes"
} else { 
// 
}

if (mathsdDate > 1) {
 lastmonthornot = "no"
} else { 
// 
}


resultYear = mathsyYear;



if(mathsdDate == 1 && mathsmMonth == 1){
  resultYear = mathsyYear - 1;
}

resultMonth = mathsmMonth


if ( mathsdDate == 1 ); {
  resultMonth = mathsmMonth - 1
}

if ( resultMonth == 0 ); {
resultMonth = 12
}


if ( resultMonth == 1 || resultMonth == 3 || resultMonth == 5 || resultMonth == 7 || resultMonth == 8 || resultMonth == 10 || resultMonth == 12 ); {
resultDate = "31"
}

if ( resultMonth == 4 || resultMonth == 6 || resultMonth == 9 || resultMonth == 11 ); {
resultDate = "30"
}

if ( resultMonth == 2 && leapyearornot == "yes" ); {
resultDate = "29"
}

if ( resultMonth == 2 && leapyearornot == "no" ); {
resultDate = "28"
}



if ( resultMonth < 10 ) ; {
endofmonth = resultDate + "-0" + resultMonth + "-" + resultYear
}


if ( resultMonth > 9 ) ; {
endofmonth = resultDate & "-" & resultMonth & "-" & resultYear
}
return endofmonth;
}

Could someone please look into this code.
Thanks.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

@smgs You are going to need to tell us what you expect this code to do vs. what this code is currently doing.

Thanks.

Thanks.

  1. Add 60 years to year.
  2. I want to get the last date of the current month entered in the initial few lines.
    If that date happen to be 1-1-XXXX
    I want it to be last 31-12-(xxxx-1)

Eg : 3-1-1959
Add 60 to 1959 = 2019
result :

31-12-209