How to list how many days for a month for a specific year in JavaScript?
As we know 30 days have September, April, June, and November. All the rest have 31, Except February, Which has 28 days clear, And 29 in each leap year.
I would need take count of leap year. Do you know any native way to fond out.. or maybe a library.. could you suggest one?
Calculate elapsed year, month and days Select a blank cell which will place the calculated result, enter this formula =DATEDIF(A2,B2,"Y") & " Years, " & DATEDIF(A2,B2,"YM") & " Months, " & DATEDIF(A2,B2,"MD") & " Days", press Enter key to get the result.
This will work too assuming Jan=1, Feb=2 ... Dec=12
function daysInMonth(month,year)
{
return new Date(year, month, 0).getDate();
}
FIDDLE
try this
function daysInMonth(m, y)
{
m=m-1; //month is zero based...
return 32 - new Date(y, m, 32).getDate();
}
usage :
>> daysInMonth(2,2000) //29
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With