Parse date in js
<script type="text/javascript"> var str1 = "3/01/2013"; var str2 = "03/2/2013"; var d1 = parseDate(str1).getTime(); var d2 = parseDate(str2).getTime(); if (d1 == d2) { alert("d1 == d2"); } else if (d1 > d2) { alert("d1 > d2"); } else { alert("d1 < d2"); } function isDate(dateString) { var date = parseDate(dateString); if (date == null) return false; return true; } function parseDate(dateString) { var delimiter = "/"; if (dateString.indexOf("-") > 0) { delimiter = "-"; } var parts = dateString.split(delimiter); if (parts.length != 3) { return null; } /* mm/dd/yyyy or mm-dd-yyyy */ var year = parts[2]; var month = parts[0] - 1; var day = parts[1]; var newDate = new Date(year, month, day); if (isNaN(newDate)) return null; if (newDate.getYear() == year && newDate.getMonth() == month && newDate.getDate() == day) { return newDate; } return null; } </script>