Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138249

Datepicker Jquery UI / Or Bootstrap Datepicker - Disable date FROM between date TO (Not specific dates)

$
0
0

i have been searching for a while now. And i can't find information about how to disable dates FROM until TO. The dates i catch from the database are booked registrations. I can't have double booked registration on dates that were earlier registred.

I could make datePicker like this because it's all over the internet. But it's not what i need.

I fetch (disabled)-dates from the database. First output comes all the dateFrom dates then after that all the dateTo dates. I am not that good at javascript, so i hope someone could help me. I want the Dates to be disabled ["12/10/2019", "12/13/2019", "12/20/2019", "12/25/2019"]. From 12/10/2019 until 12/20/2019 and 12/13/2019 until 12/25/2019. And so on, it could be 10 dates that i would fetch right here (5 dateFroms and 5 dateTo's). Is there a solution for this? I am losing my hope after searching +-5 hours long. Hope someone could answer me i am very thankfull for your time and effort.

 $(function() {
   var disableddates = [<?php    $str = '';
      while ($output = $statement->fetch(PDO::FETCH_ASSOC)) {


             $str .= "'".$output["dateTo"]."',";
             $str .= "'".$output["dateFrom"]."',";
             //echo "'$car_name',";

         }
         echo rtrim($str,",");?>];

   $("#from, #to").datepicker({
     minDate: 0,
     beforeShowDay: DisableSpecificDates,
     dateFormat: "m/d/yy"
   });

   $("#from").change(function() {
     $("#to").datepicker("option", "minDate", $(this).val());
   });

   function DisableSpecificDates(date) {
     var result = [true];
     $.each(disableddates, function(k, v) {
       var exclude = new Date(v).toString();
       var today = date.toString();
       if (exclude == today) {
         console.log("Match", exclude, today);
         result = [false];
       }
     });
     return result;
   }
 });

Viewing all articles
Browse latest Browse all 138249

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>