javascript - convert string to Date object and compare in js -
how can compare 2 dates format
var currdate = new date().format("mm/dd/yyyy"); if (date.parse("05-jun-2012")>date.parse(currdate)) { alert("please enter future date!"); return false; } please validate date.
function customparse(str) { var months = ['jan','feb','mar','apr','may','jun', 'jul','aug','sep','oct','nov','dec'], n = months.length, re = /(\d{2})-([a-z]{3})-(\d{4})/i, matches; while(n--) { months[months[n]]=n; } // map month names index :) matches = str.match(re); // extract date parts string return new date(matches[3], months[matches[2]], matches[1]); } customparse("18-aug-2010"); // "wed aug 18 2010 00:00:00" customparse("19-aug-2010") > customparse("18-aug-2010");
Comments
Post a Comment