Skip to content Skip to sidebar Skip to footer

Java Script check date range is valid or not

Reading Time: < 1 minute

Q:- I want to validate date range or if exist date range by using java script.
Answer :-
This is can be done using Date() object.Look at the following function.It will return date range is valid or not.Simply you have to pass start date and end date only.

  function endAfterStart(startDate,endDate){
     return new Date(startDate.split('/').reverse().join('/')) <= new Date(endDate.split('/').reverse().join('/'));
  }
  alert(endAfterStart('10/07/2012','30/07/2012')); //=> true
  alert(endAfterStart('30/07/2012','10/07/2012')); //=> false

You can check this using console panel of the firebug.