0

I have a variable and inside of it is a date in which i get it from my database and I just want to ask how to use it in my datepicker using minDate and maxDate here is my code:

<?php
include ('connection.php');
$count = 1;
$query = "SELECT * FROM tblPaymentDetails WHERE CustomerID = '$count'";

$run = mysqli_query($con, $query);

if(mysqli_num_rows($run)>= 1){
    $row = mysqli_fetch_assoc($run);
    $CheckInDate = "$row[CheckInDate]";
    $CheckOutDate = "$row[CheckOutDate]";
}

else{
    echo"error";
}
?>
<script> $(function() {
        $( "#txtCheckOutDate" ).datepicker({ minDate: new     Date($CheckInDate), maxDate: new Date($CheckOutDate)});
    });
</script>

2 Answers2

0

No,need to use new Date($date).You can use simple code as following

$(document).ready(function ()
 {
    $( "#arrival_date" ).datepicker();
    $( "#arrival_date" ).datepicker('option','minDate','7/29/2012');  
    $( "#arrival_date" ).datepicker('option','maxDate','7/29/2013');  

});

Here a working example: http://jsfiddle.net/ZTnr5/1/

You have to define the datepicker before setting the option and you must quote the date string.

Runcorn
  • 5,144
  • 5
  • 34
  • 52
DeepakJ
  • 378
  • 4
  • 14
0

You might find this post helpful: How to embed php in javascript?

As for your specific example, you'd go along the lines of:

<script>
    $(function() {
        $( "#txtCheckOutDate" ).datepicker({
            minDate: new Date(
                 <?php echo $CheckInDate; ?>
            ),
            maxDate: new Date(
                 <?php echo $CheckInDate; ?>
            )
        });
    });
</script>
Community
  • 1
  • 1
blgt
  • 8,135
  • 1
  • 25
  • 28