Skip to content

Compare two date

Manuel Joseph

Asked Feb 16, 2012, 10:48 PM EST2 answers
Share
LinkedInX
Dear sir,

       How to compare two date format validate find that date  and date greater 30 days in javascript

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Ghanashyam Nayak
    0
    You have to use the Regex to validate the date. use below code to check the valid date : var matches = this.match(/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/); if (!matches) return false; in the above code if the date is not valid then return false. otherwise you have to write you logic. Now you have to check that is date > 30, so for that you have to use below code : if(matches[2] > 30) return false; In the above code if the day is grater than the 30 then it will return false. otherwise you have to write your logic. On more thing you have to check while comparing two dates and that is the "toDate" must be less than the "fromDate". so for that use below code : if (Date.parse(fromDate) > Date.parse(toDate)) { alert("Invalid Date Range!\nStart Date cannot be after End Date!") return false; } Hope this will help you....
    0
  • 1 short reply
    • Suthish Nair
      0
      Thread resolved?
      0