How to enable only the last days of the months using Datepicker jQuery?

So my question is pretty simple. I would like to have specific dates that are included on the datepicker, e.g. http://tokenposts.blogspot.fr/2011/05/jquery-datepicker-disable-specific.html , but I only want the last day of any month, e.g. 30 / 06/2012, 07/31/2012, ...

Any clue?

+5
source share
1 answer

Here is how you can do it ...

Getting the last day for a given year and month:

function getLastDayOfYearAndMonth(year, month)
{
    return(new Date((new Date(year, month + 1, 1)) - 1)).getDate();
}

Pay attention to the beforeShowDayevent if the date is the last month:

$('.selector').datepicker(
{
    beforeShowDay: function(date)
    {
        // getDate() returns the day [ 0 to 31 ]
        if (date.getDate() ==
            getLastDayOfYearAndMonth(date.getFullYear(), date.getMonth()))
        {
            return [true, ''];
        }

        return [false, ''];
    }
});
+3
source

All Articles