0

How can compare two dates like this 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 help to validate date.

Justinonday
  • 137
  • 3
  • 15
  • http://stackoverflow.com/questions/3509683/validate-two-dates-of-this-dd-mmm-yyyy-format-in-javascript A duplicate question. find your answer here. – Neha Jun 04 '12 at 13:01

1 Answers1

1
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 to their index :)

  matches = str.match(re); // extract date parts from 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");
Neha
  • 2,933
  • 3
  • 19
  • 23