I need a function where I send a year and a month (The year for february - leap year) and it returns me the last day of the month. Does anyone has any?
//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;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.