Keep it simple:
[ edit ] correctly, you also need a check, so fn chkDat added:
function zeroPad(n){ return (parseInt(n,10)<10 ? '0' : '') + n; } var usdat = '5/19/2011'.split('/') ,eudat = [usdat[2],zeroPad(usdat[0]),zeroPad(usdat[1])]; alert(chkDat(usdat,eudat); //=> true alert(eudat.join('-')); //=> '2011-05-19' function chkDat(orig,eu){ var eu = new Date(eu.join('/')); return eu.getMonth()+1 === parseInt(orig[0],10) && eu.getDate() === parseInt(orig[1],10) && eu.getFullYear() === parseInt(orig[2],10) ; }
Note The date format you use is called the calendar date ( ISO 8601 ).
source share