function dateDiff(part, date1, date2){
    var returnVal;
    switch(part){
        case 'd':
            returnVal = parseInt((date2.getTime()-date1.getTime())/(24*3600*1000));
            break;
        case 'w':
            returnVal = parseInt((date2.getTime()-date1.getTime())/(24*3600*1000*7));
            break;
        case 'm':
            returnVal = (date2.getMonth() + 12 * date2.getFullYear()) - (date1.getMonth() + 12 * date1.getFullYear());
            break;
        case 'y':
            returnVal = date2.getFullYear() - date1.getFullYear();
            break;
        default:
            alert('Unknown date part');
            break;
    }
    return returnVal;
}
/*
**    Description:    Calculates the difference between two dates' specified date part
**    Arguments:        part (string) - the part of the date to be used for comparison. Currently supports 'd' (days), 'w' (weeks), 'm' (months), 'y' (years)
**                    date1 (dateTime) - the earlier of the two dates
**                    date2 (dateTime) - the later of the two dates
*/
Calculates the difference between two dates' specified date part
Arguments:        part (string) - the part of the date to be used for comparison.
Calculates the difference between two dates ' specified date part Arguments : part ( string ) - the part of the date to be used for comparison .
function dateDiff(part, date1, date2){
    var returnVal;
    switch(part){
        case 'd':
            returnVal = parseInt((date2.getTime()-date1.getTime())/(24*3600*1000));
            break;
        case 'w':
            returnVal = parseInt((date2.getTime()-date1.getTime())/(24*3600*1000*7));
            break;
        case 'm':
            returnVal = (date2.getMonth() + 12 * date2.getFullYear()) - (date1.getMonth() + 12 * date1.getFullYear());
            break;
        case 'y':
            returnVal = date2.getFullYear() - date1.getFullYear();
            break;
        default:
            alert('Unknown date part');
            break;
    }
    return returnVal;
}
function dateDiff ( part , date1 , date2 ) { var returnVal ; switch ( part ) { case 'd' : returnVal = parseInt ( ( date2 . getTime ( ) - date1 . getTime ( ) ) / ( 24 * 3600 * 1000 ) ) ; break ; case 'w' : returnVal = parseInt ( ( date2 . getTime ( ) - date1 . getTime ( ) ) / ( 24 * 3600 * 1000 * 7 ) ) ; break ; case 'm' : returnVal = ( date2 . getMonth ( ) + 12 * date2 . getFullYear ( ) ) - ( date1 . getMonth ( ) + 12 * date1 . getFullYear ( ) ) ; break ; case 'y' : returnVal = date2 . getFullYear ( ) - date1 . getFullYear ( ) ; break ; default : alert ( 'Unknown date part' ) ; break ; } return returnVal ; }
Description:    Calculates the difference between two dates' specified date part
Arguments:        part (string) - the part of the date to be used for comparison.
Description : Calculates the difference between two dates ' specified date part Arguments : part ( string ) - the part of the date to be used for comparison .