title: Javascript Booking Calculator Not Counting 24 Hours As 1 Day
body: <p>I've created a booking calculator by date using JavaScript.</p>
  
  <p>Basically I want the base price to be £25 for 1 day (24 hours) or less, and £10 for each additional day (each additional 24 hours).</p>
  
  <p>Below is the main part of the code.</p>
  
  <pre><code>jQuery(document).ready(function($) {
  
  var prequote=25.00;
  var taxa = 10.00;
  var hoje = new Date();
  hoje=hoje.getTime();
  i = 0;
  
   $('#quote').click(function(event) {
  
      var d1= $('#d1').val();
      var d2= $('#d2').val();
      var t1= $('#t1').val();
      var t2= $('#t2').val();
  
      console.log(d1);
      console.log(d2);
      console.log(t1);
      console.log(t2);
  
      // end - start returns difference in milliseconds 
      var date2 = new Date(d2);
      var date1 = new Date(d1);
      var millisecondsPerDay = 1000 * 60 * 60 * 24;
      var millisBetween = date2.getTime() - date1.getTime();
      // get days
      var d = millisBetween / millisecondsPerDay;
      //alert ('value of days is:' +d);
      //alert ( new Date("1970-1-1 " + t2) - new Date("1970-1-1 " + t1) ) / 1000 / 60 / 60;
      var h= ( new Date("1970-1-1 " + t2) - new Date("1970-1-1 " + t1) ) / 1000 / 60 / 60; 
      //alert ('value of hours is:' +h);      
       t1 =t1.split(':');
       t2 =t2.split(':');
  
  
      var dat1 = d1.split("-"); 
      var dd1 = dat1[2];
      var mm1 = dat1[1];
      var yy1 = dat1[0];
      var hh1 = t1[0];
      var ms1 = t1[1];
  
      var dat2 = d2.split("-"); 
      var dd2 = dat2[2];
      var mm2 = dat2[1];
      var yy2 = dat2[0];
      var hh2 =t2[0];
      var ms2 = t2[1];
  
  
       var x1 = yy1 + ',' + mm1 + ',' + dd1 + ' ' + hh1 + ':' + ms1;
       var x2 = yy2 + ',' + mm2 + ',' + dd2 + ' ' + hh2 + ':' + ms2;
  
       var ent = dd1 + '/'+ mm1 +'/'+yy1+' '+ hh1 + ':' + ms1;
       var ext = dd2 + '/'+ mm2 +'/'+yy2+' '+ hh2 + ':' + ms2;
  
  
       var xi = yy1 + ',' + mm1 + ',' + dd1 ;
       var xj = yy2 + ',' + mm2 + ',' + dd2 ;
  
  
        var start =new Date(x1);
        //var start_i =new Date(xi);
        var end = new Date(x2);
       // var end_i = new Date(xj);
        start = start.getTime();
        end= end.getTime(); 
        if(start === end){
              alert('Min rental days is 1');
          }
          else if(start &lt; end){
              //  hh1 = parseInt(hh1);ms1 = parseInt(ms1);hh2 = parseInt(hh2);ms2 = parseInt(ms2);;
                  /*while(start_i &lt; end_i){
                       i++;
                       var newDate = start_i.setDate(start_i.getDate() + 1);
                         start_i = new Date(newDate);                           
                  }*/
  
                  i=d;
                  if(i &gt;= 1 ){
                      if(h &gt; 0 ){
                          i=i+1;
                      }
                      prequote = prequote + (taxa * (i-2));
                      prequote =  parseFloat(prequote.toFixed(2));
                  }    
  
                   $('#en-tex').text(ent);
                   $('#ex-t').text(ext);
                   $('#prequote').html(prequote);
                   $('#modal-img').modal('show'); 
                   prequote=25.00;
  
                  $('#tupd').val(ent);
                  $('#tdod').val(ext);
          }
          else{
              alert('Please fill in all the date and time fields.');
          }
  
  
   });
  </code></pre>
  
  <p>The 1st issue is, if I select for example Monday 21st at 9:00am to Tuesday 22nd at 9:00am it doesn't count the fee as for 24 hours. Only if the end date is AFTER 9:00am.</p>
  
  <p>Likewise for longer dates, it only charges for a day AFTER 24 hours and not from 24 hours on the dot.</p>
  
  <p>2nd issue is, if somebody selects less than 24 hours (i.e Monday 21st at 9:00am to Tuesday 22nd at 7:00am) it minuses the £10 from £25. I want it to still quote the base price of £25.</p>