Tuesday, September 15, 2015
Get the last day of the month from a specific date using JavaScript
Let’s say we have given any date and we want to find out on what day of the week the Month ends using Javascript. E.g. 09-12-2015 (12th Sept 2015), the last day of this month is Wednesday. So our script should return 3 which is Wednesday counting from Sunday as 0, Monday as 1, Tuesday as 2 & so on.
Here is the script that I made :
var my_date = new Date('12-25-2015'); var last_of_month = new Date( my_date.getFullYear(), my_date.getMonth()+1, 0 ); var day_of_week = last_of_month.getDay();
And day_of_week will have the last day of the month.