PDA

View Full Version : get days of a month


webreake
06-15-2005, 07:37 AM
hi
im getting a problem when i try to get the days of a month here is my function:
function days(year, month) {
var thisMonth = new Date(year, month);
var nextMonth = new Date(year, month+1);
var Ndays = ((((nextMonth-thisMonth)/1000)/60)/60)/24;
return Ndays;
}

in september and november i get 31 days
I didnt try yet the Math.round but i want to know if
there is a better way to do this ?

tg
06-15-2005, 02:06 PM
http://proto.layer51.com/d.aspx?f=1322

jsebrech
06-15-2005, 02:26 PM
Beware that the month variable to date functions (like new Date()) starts from 0, so january is 0, februrary is 1, and so on.

webreake
06-15-2005, 07:39 PM
thanks for the answers
the method works great

flashDuniya
02-03-2009, 09:07 AM
hi
im getting a problem when i try to get the days of a month here is my function:
function days(year, month) {
var thisMonth = new Date(year, month);
var nextMonth = new Date(year, month+1);
var Ndays = ((((nextMonth-thisMonth)/1000)/60)/60)/24;
return Ndays;
}

in september and november i get 31 days
I didnt try yet the Math.round but i want to know if
there is a better way to do this ?

This is the very simple code to find the number of days in a month

function showDays(yr, mn){
var days:Date = new Date(yr, mn+1, 0);
trace(days.date);// It will trace total no. of days(28) in a month
}
showDays(2009, 1);// 1=February

Thanks,
flashDuya.com

peptobismol
08-13-2010, 02:54 PM
This is the very simple code to find the number of days in a month

function showDays(yr, mn){
var days:Date = new Date(yr, mn+1, 0);
trace(days.date);// It will trace total no. of days(28) in a month
}
showDays(2009, 1);// 1=February

Thanks,
flashDuya.com

this doesn't work...
here's another one I found that's JS but works for AS too.

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

trace(daysInMonth(1, 2009));