How to get last date of the month – javascript

Author: satz | Date: May 16, 2011

The following function will return the last date of the month. This function is very much useful while calculating the last date of a particular month. The arguments passed into the function should be number.

This function returns the last date of the month using JavaScript.

Get the last date of the month – JS

Function

function getLastDateOfMonth(Year,Month){
 return(new Date((new Date(Year, Month+1,1))-1));
 }

Usage

getLastDateOfMonth(2011,1)

The above sample will return Mon Feb 28 2011 23:59:59 GMT. Thisis a simple function which returns the last date of the month. It returns the last date as a date object.