Date Leap Year Validation
function checkDate(date) { //how to use this function since many people recommend this one isLeap = new Date(date, 1, 29).getMonth() == 1; return isLeap; } In ht
Solution 1:
To check if it's leap year :
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
to check if the extra day is valid -- is to check how many days were in that month (and if they equal to dd):
32 - new Date(2000, 1, 32).getDate()
//1 here is FEB
do if some says : 29 feb 2000
so
32 - new Date(2000, 1, 32).getDate()
//29
which is fine . cuz 29==29.
BUT
do if some says : 29 feb 2001
32 - new Date(2001, 1, 32).getDate()
//28
and 28!=29 so it's not valid date.
Post a Comment for "Date Leap Year Validation"