I want to validate my date if date not exits in calendar then return me last available date of calendar,
Example 01
Input Date : 31
function isValidDate(year, month, day) {
if(month<=12){
var temp_day=day;
var d = new Date(year, month, day);
var lastDay = new Date(d.getFullYear(), d.getMonth(),0);
var getlastday=lastDay.getDate();
if(getlastday<=day){
//var date=(d.getDate())+"/"+(d.getMonth())+"/"+(d.getFullYear());
var date=(getlastday)+"-"+(month)+"-"+(lastDay.getFullYear());
return date;
}else{
//var date=(lastDay.getDate())+"-"+(lastDay.getMonth())+"-"+(lastDay.getFullYear());
var date=(day)+"/"+(month)+"/"+(year);
return date;
}
}
else{
return "month not valid";
}
}
try this code