I've been using this function but I'd like to know what's the most efficient and accurate way to get it.
function daysInMonth(iMonth, iYear) {
return 32 - new Date(iYear, iMonth, 32).getDate();
}
I've been using this function but I'd like to know what's the most efficient and accurate way to get it.
function daysInMonth(iMonth, iYear) {
return 32 - new Date(iYear, iMonth, 32).getDate();
}
How about a lookup table, with a little special casing for February in leap years?
function daysInMonth(month,year)
{
return new Date(year, month, 0).getDate();
}
Day 0 is the last day in the previous month. Because the month constructor is 0 based, this works nicely. A bit of a hack, but that's basically what your doing by subtracting 32.