This is a discussion on Number of days in a month (or last day of a month) within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all... Can anyone tell me how can i find the number of days in a month (or last day ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi all... <script language="JavaScript"> var daysofmonth = new makeArray( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var daysofmonthLY = new makeArray( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); function LeapYear(year) { if ((year/4) != Math.floor(year/4)) return false; if ((year/100) != Math.floor(year/100)) return true; if ((year/400) != Math.floor(year/400)) return false; return true; } function y2k(number) { return (number < 1000) ? number + 1900 : number; } var today = new Date(); var year = y2k(today.getYear()); if (LeapYear(year) { daysofmonth = daysofmonthLY; } alert('February ' + year + ' has ' + daysofmonth[1] + ' days'); </script> Thanks... |
| |||
| function daysInMonth(month,year) { var m = [31,28,31,30,31,30,31,31,30,31,30,31]; if (month != 2) return m[month - 1]; if (year%4 != 0) return m[1]; if (year%100 == 0 && year%400 != 0) return m[1]; return m[1] + 1; } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Find the last day of the month for any given month. | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 03-17-2008 08:56 PM |
| Calculate how many hours per each month | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 02-25-2008 09:23 PM |
| calculate the number of days in the current month | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 02-08-2008 06:30 AM |
| Get Last Day of the Month Function | srikumar_l | Database Support | 0 | 12-21-2007 08:40 PM |
| Get First Day of the Month Function | srikumar_l | Database Support | 0 | 12-21-2007 08:37 PM |