function getLastDayOfMonth(year, month){ var date = new Date (year, month); var dateM=date.getMonth(); var i = 28; while (dateM==month){ date.setDate(++i); dateM=date.getMonth(); } return --i; }; alert(getLastDayOfMonth(2012, 1));