title: Date comparison and validation in Javascript
body: <p>I need to validate whether the date mentioned should be greater than or equal to the current date. But problem here is if user is giving old date '03/11/0018', by default the year gets considered as 2018(as per the below code).
  One way which I did is to take the input data and get the year using substring and handle(not mentioned in the below code).
  Is there any other way to handle this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>    &lt;html&gt;
      &lt;head&gt;
      &lt;script&gt;
      function dateCompare() {
         var d1 = new Date('03/11/0018'); 
         var d2 = new Date('03/11/2018'); //consider today's date is 03/11/2018
         if(d1 &lt; d2){
             //validate the input date
             document.write("entered date cannot be earlier to the current date");
         }
         else{
             //validation passed
             document.write("Ideally 03/11/0018 is earlier than 03/11/2018 &amp; validation should be failed");
         }
      }
      dateCompare();
      &lt;/script&gt;
      &lt;/head&gt;
      &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>