Rate this script:  I Love it  /   I Hate it

Determining the Number of Days in a Month with Javascript


Code


function daysInMonth(iMonth, iYear)
{
        return 32 - new Date(iYear, iMonth, 32).getDate();
}

<button onclick="alert(daysInMonth(1, 2100));">February 2100</button>
<button onclick="alert(daysInMonth(1, 2005));">February 2005</button>
<button onclick="alert(daysInMonth(1, 2004));">February 2004</button>
<button onclick="alert(daysInMonth(1, 2003));">February 2003</button>
<button onclick="alert(daysInMonth(1, 2001));">February 2001</button>
<button onclick="alert(daysInMonth(1, 2000));">February 2000</button>
<button onclick="alert(daysInMonth(1, 1999));">February 1999</button>
 

 

 
Determining the Number of Days in a Month with Javascript scripts | Determining the Number of Days in a Month with Javascript snippet | Determining the Number of Days in a Month with Javascript example | Determining the Number of Days in a Month with Javascript tutorial | Determining the Number of Days in a Month with Javascript code