Jump to content

function that return num of days in month


kfir91

Recommended Posts

function getDays() {
var intMonth = getFullYear[document.getElementById('month').innerHTML];
var intYear = document.getElementById('year').innerHTML;
var dteMonth = new Date(intYear,intMonth);
var intDaysInMonth = 28;
var blnDateFound = false;
while (!blnDateFound) {
	dteMonth.setDate(intDaysInMonth+1);
	var intNewMonth = dteMonth.getMonth();
	if (intNewMonth != intMonth)
		blnDateFound = true;
	else
		intDaysInMonth++;
}
return intDaysInMonth;
}

 

i tried this.. but its return invalid nums...

how i do function that return num of days in month if i have month in num and year in num.

Link to comment
Share on other sites

I'm pretty sure that first line is invalid. I'm really not making sense of your code, but...

 

Assuming you have the year and the month as numerical values, this function will return the number of days in that month:

 

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

 

I do not take credit for this. I lifted this code from here: http://snippets.dzone.com/posts/show/2099

Link to comment
Share on other sites

No offense, but your first response states it is not returning anything, then your second response states it's returning the wrong values. So, forgive me if I don't trust your results.

 

Based on the logic, i see no reason it would not work. You do know that in Javascript the months are numerically based starting at zero (0), right?

 

January = 0, February = 1, etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.