kfir91 Posted June 19, 2009 Share Posted June 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162969-function-that-return-num-of-days-in-month/ Share on other sites More sharing options...
Psycho Posted June 19, 2009 Share Posted June 19, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/162969-function-that-return-num-of-days-in-month/#findComment-859904 Share on other sites More sharing options...
kfir91 Posted June 19, 2009 Author Share Posted June 19, 2009 its return null.. its not return nothing Quote Link to comment https://forums.phpfreaks.com/topic/162969-function-that-return-num-of-days-in-month/#findComment-859907 Share on other sites More sharing options...
kfir91 Posted June 19, 2009 Author Share Posted June 19, 2009 its return invalid nums too... like in june have 31 days and have 30 ... and jan 28 days and there is 31... Quote Link to comment https://forums.phpfreaks.com/topic/162969-function-that-return-num-of-days-in-month/#findComment-859912 Share on other sites More sharing options...
Psycho Posted June 20, 2009 Share Posted June 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162969-function-that-return-num-of-days-in-month/#findComment-859945 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.