Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of Days in a Month 1

Status
Not open for further replies.

mitch77

Programmer
Nov 16, 2000
42
PT
there are any function in javascript, to count the number of days in a month?

thanks,
Mitch Jeffers
 
I don't think there is a native method to complete this. jared@aauser.com
 
I don't think javascript supplies a method for this either, but you can write your own. For example:

function isLeapYear(y)
{
return (y%4==0 && y%100!=0) || y%400==0;
}
function daysInMonth(m,y)
{
if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) {
return 31;
} else if (m==4 || m==6 || m==9 || m==11) {
return 30;
} else {
return isLeapYear(y) ? 29 : 28;
}
}

// Get # of days in February for the current year
var md=daysInMonth(2,new Date().getYear());

HTH,

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top