Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
731 B
11
Indexable
Never
// get the input value from the textbox
let inputVal = "05/2023"; // for example

// parse the input string into a Date object
let dateObj = new Date(inputVal);

// set the date to the first day of the next month
dateObj.setMonth(dateObj.getMonth() + 1, 1);

// subtract one day to get the last day of the current month
dateObj.setDate(dateObj.getDate() - 1);

// get the day of the week (0-6, where 0 is Sunday and 6 is Saturday)
let lastDayOfWeek = dateObj.getDay();

// an array of day names (0-6)
let dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

// get the name of the last day of the month
let lastDayName = dayNames[lastDayOfWeek];

// print the result
console.log(lastDayName);