Try using the javascript date object:
function fnDate_LastDay(i_nMonth, i_nYear) {
//construct a date, 1st of the NEXT month
// the month parameter is 0-11!
var dt = new Date(i_nYear, i_nMonth, 1);
//subtract 1 day from date
//to get last day of previous month...
dt.setDate(-1);
return dt.getDate() + 1; //getDate returns 0-30!
}
or use the dateadd function in vb script:
dim dt
dt = DateSerial (i_nYear, i_nMonth + 1, 1)
'can cope with month 13!
DateAdd("d",-1,dt)
fnDate_LastDay = Day(dt)
These may be slightly slower than typical code - but it is much more accurate (for those odd leap years):
function getNoOfDaysInMnth(i_nMnth, i_nYr) {
/*
** Get the number of days in the month based on the year.
** [Rather simplistic function, as it ignores some special cases]
*/
var rem = i_nYr % 4; //use modulo 4 for leap year
var leap = 0;
var noDays=0;
if (rem ==0)
leap = 1;
if ( (i_nMnth == 4) || (i_nMnth == 6) || (i_nMnth == 9) ||
(i_nMnth == 11)) {
noDays=30;
} else if (i_nMnth == 2) {
noDays=28+leap;
} else {
noDays=31;
}
return noDays;
}