Javascript checkdate : Date and Time : PHP functions in JavaScript JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » PHP functions in JavaScript » Date and Time »

 

Javascript checkdate


Returns true(1) if it is a valid date in gregorian calendar
Example 1

Running
1.checkdate(12, 31, 2000);

Could return
1.true
Example 2

Running
1.checkdate(2, 29, 2001);

Could return
1.false
function checkdate( month, day, year ) {
    // Returns true(1) if it is a valid date in gregorian calendar  
    // 
    // version: 810.114
    // discuss at: http://phpjs.org/functions/checkdate
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Pyerre
    // *     example 1: checkdate(12, 31, 2000);
    // *     returns 1: true
    // *     example 2: checkdate(2, 29, 2001);
    // *     returns 2: false
    // *     example 3: checkdate(03, 31, 2008);
    // *     returns 3: true
    // *     example 4: checkdate(1, 390, 2000);
    // *     returns 4: false
    var myDate = new Date();
    myDate.setFullYear( year, (month - 1), day );

    return ((myDate.getMonth()+1) == month && day<32); 
}


HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo PHP functions in JavaScript
» Date and Time