Feedback on: irt.org FAQ Knowledge Base Q533
Comments:Here is an example on how to use the script
<form><script>function days_in_month (year, month) { return 32 - new Date(year, month, 32).getDate();}now = new Date();daysInMonth = days_in_month(now.getFullYear(),now.getMonth());txt='<select name="days">';for (i=1;i<=daysInMonth;i++) txt += 'txt+='</select>';document.write(txt)</script></form> Sent by Jeff Boulton on September 05, 2001 at 10:41:18: - feedback #3128Worth: Very worth readingComments:Very cool. But unless I am missing something the day number is zero based. ie: February is "1"THANXSent by W on September 29, 2002 at 20:07:38: - feedback #4177Worth: Not worth readingLength: Too shortComments:Hey!What value does newdate have?! Are the variables being multiplied by newdate then added together or are they being manipulated on some other way?! What language is this written in?! What is the point in posting this without any type of explanation. Does the individual who posted this think everyone has the same knowledge as they? Or is it if they don't already know then they have no business looking here anyway?! If this is a fair sample of your database I propose that it must be a usless waste of storage space!!!!!!!!Sent by Pankaj Jain on November 13, 2002 at 14:28:25: - feedback #4265Technical: Not technical enoughComments:It is a clever peice of code, but it looks like it is using a so called BUG in the Date() object. Ideally if you pass day as 32 it should give you error. Think when this bug is fixed and your program will stop working; you will have tough time finding this error.Sent by Giacomo on Tuesday July 10, 2007 at 00:12:03 - feedback #4793Worth:Very worth readingLength:Just rightTechnical:Just rightComments:Why not try var date = new Date();date.setMonth(2,0);var numberOfDaysInJanuary = date.getDate();Sent by Daniel Ansari on Friday November 23, 2007 at 01:32:57 - feedback #5156Worth:Worth readingLength:Just rightTechnical:Just rightComments:Here's a safer method:function daysInMonth(dt) { var endNextMonth = new Date(dt); endNextMonth.setDate(1); endNextMonth.setMonth(dt.getMonth() + 1); endNextMonth.setDate(0); var daysInEndMonth = endNextMonth.getDate(); return daysInEndMonth;}Sent by Avinash on Sunday February 24, 2008 at 20:17:48 - feedback #5219Worth:Very worth readingLength:Just rightTechnical:Just rightComments:Excellent, short and precise©2018 Martin Webb
Worth: Very worth reading
Comments:Very cool. But unless I am missing something the day number is zero based. ie: February is "1"
THANX
Worth: Not worth reading
Length: Too short
Comments:Hey!What value does newdate have?! Are the variables being multiplied by newdate then added together or are they being manipulated on some other way?! What language is this written in?! What is the point in posting this without any type of explanation. Does the individual who posted this think everyone has the same knowledge as they? Or is it if they don't already know then they have no business looking here anyway?! If this is a fair sample of your database I propose that it must be a usless waste of storage space!!!!!!!!
Technical: Not technical enough
Comments:It is a clever peice of code, but it looks like it is using a so called BUG in the Date() object. Ideally if you pass day as 32 it should give you error. Think when this bug is fixed and your program will stop working; you will have tough time finding this error.
Worth:Very worth reading
Length:Just right
Technical:Just right
Comments:Why not try var date = new Date();date.setMonth(2,0);var numberOfDaysInJanuary = date.getDate();
Worth:Worth reading
Comments:Here's a safer method:function daysInMonth(dt) { var endNextMonth = new Date(dt); endNextMonth.setDate(1); endNextMonth.setMonth(dt.getMonth() + 1); endNextMonth.setDate(0); var daysInEndMonth = endNextMonth.getDate(); return daysInEndMonth;}
Comments:Excellent, short and precise
©2018 Martin Webb