title: How to Validate Date and Time with JavaScript
body: <p>This code below is suppose to show an alert box if an incorrect date and/or time is selected. </p>
  
  <p>The problem I'm having is, If I selected 25/11/2015 and choose 11:00 It shows "Please change date or Time". If I then select 25/11/2015 and choose 21:00 it shows "That's Fine".</p>
  
  <p>The function is ignoring the date and just checking the time.</p>
  
  <p>It should show a message saying "Please change date or time" if the user selects a time that is gone already or a date that is before today. </p>
  
  <p>I hope I can get help with this issue. Thanks in advance.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function myFunction() {
    var today = new Date();
    var select_text = document.getElementById("datepicker-leave").value;
    var select_date = new Date(select_text);
    var select_time = document.getElementById("leavedrop").value;
    var curr_time = today.getHours() + 1;
  
    if ((select_date.getTime() &lt;= today.getTime()) &amp;&amp; select_time &lt; curr_time) {
      alert("Please change Date or Time")
    } else {
      alert("That's Fine")
    }
  }
  
  &lt;script&gt;
    $(function() { //datepickers
        $( "#datepicker-leave).datepicker({            
          dateFormat: 'd-M-yy'}); 
     });
  &lt;/script&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text" id="datepicker-leave"&gt;
  
  &lt;select id="leavedrop"&gt;
    &lt;option value="0"&gt;00:00&lt;/option&gt;
    &lt;option value="1"&gt;01:00&lt;/option&gt;
    &lt;option value="2"&gt;02:00&lt;/option&gt;
    &lt;option value="3"&gt;03:00&lt;/option&gt;
    &lt;option value="4"&gt;04:00&lt;/option&gt;
    &lt;option value="5"&gt;05:00&lt;/option&gt;
    &lt;option value="6"&gt;06:00&lt;/option&gt;
    &lt;option value="7"&gt;07:00&lt;/option&gt;
    &lt;option value="8"&gt;08:00&lt;/option&gt;
    &lt;option value="9"&gt;09:00&lt;/option&gt;
    &lt;option value="10"&gt;10:00&lt;/option&gt;
    &lt;option value="11"&gt;11:00&lt;/option&gt;
    &lt;option value="12"&gt;12:00&lt;/option&gt;
    &lt;option value="13"&gt;13:00&lt;/option&gt;
    &lt;option value="14"&gt;14:00&lt;/option&gt;
    &lt;option value="15"&gt;15:00&lt;/option&gt;
    &lt;option value="16"&gt;16:00&lt;/option&gt;
    &lt;option value="17"&gt;17:00&lt;/option&gt;
    &lt;option value="18"&gt;18:00&lt;/option&gt;
    &lt;option value="19"&gt;19:00&lt;/option&gt;
    &lt;option value="20"&gt;20:00&lt;/option&gt;
    &lt;option value="21"&gt;21:00&lt;/option&gt;
    &lt;option value="22"&gt;22:00&lt;/option&gt;
    &lt;option value="24"&gt;23:00&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;input type="button" value="Submit" onClick="myFunction()" /&gt;</code></pre>
  </div>
  </div>
  </p>