0

Can someone please tell me how I can make the datepicker pick a date that is after a certain date I choose.

For example I want the date picker to pick dates after 03/08/2012.

Here is my simple datepicker:

<script type="text/javascript">
$(function(){
   $("#date").datepicker({ dateFormat: 'm/d/yy', minDate: 0});
});
</script>

What if the date was stored in a php variable. for eg. $var='03/08/2012'. Is splitting it one by one only way to do it?

I am trying to get the date from a dynamic php variable. For eg:

<script type="text/javascript">

$(function() {
    $( "#date" ).datepicker({ minDate: new Date(<?php echo $split_date[2];?>, <?php echo ($split_date[0] - 1);?>, <?php echo $split_date[1]; ?>)});
});

</script>

<?php
 $date='03/08/2011';

$split_date=explode("/",$date);
echo $split_date[0];
echo $split_date[1];
echo $split_date[2]; 
?>

but nothing i tried so far works!

Micheal
  • 2,272
  • 10
  • 49
  • 93

2 Answers2

1

According to jQuery's doc on the Datepicker, you should do

<script>
$(function() {
    $( "#datepicker" ).datepicker({ minDate: -20, maxDate: "+1M +10D" });
});
</script>

Restrict the range of selectable dates with the minDate and maxDate options. Set the beginning and end dates as actual dates (new Date(2009, 1 - 1, 26)), as a numeric offset from today (-20), or as a string of periods and units ('+1M +10D'). For the last, use 'D' for days, 'W' for weeks, 'M' for months, or 'Y' for years.

If you want it to start from 03/08/2012, you should write

<script>
$(function() {
    $( "#datepicker" ).datepicker({ minDate: new Date(2012, 3 - 1, 8)});
});
</script>

You can also refer to this answer: changing minDate option in JQuery DatePicker not working

Community
  • 1
  • 1
pgratton
  • 663
  • 4
  • 14
0

Try:

<script type="text/javascript">
$(function(){
    $("#date").datepicker({
        'dateFormat': 'm/d/yy',
        'minDate': new Date(<?php echo date('Y, m, d'); ?>)
    });
});
</script>
pete
  • 24,141
  • 4
  • 37
  • 51