0

I have DB mysql with column date_in and date_out

how to set datepicker to show available only dates from database mysql. i have two inputs with datepicker

<input type="text" name="check_in_date" id="check_in" />
<input type="text" name="chek_out_date" id="check_out" />

for example i have check_in_dates = 10-05-2012, 13-05-2012, ... , n. and they must be only available to pick through jQuery.datepicker.

mprabhat
  • 20,107
  • 7
  • 46
  • 63
Petro Popelyshko
  • 1,353
  • 1
  • 15
  • 38

2 Answers2

2

jQuery datepicker has a minDate and maxDate, so you can parse your max and min date from MYSQL and set calendar minDate and maxDate like:

minDate: new Date(year,month,day),
maxDate: new Date(eyear,emonth,eday)

In this case your calendar will show dates only in the region provided.

Hope this helps.

As per comments:

jQuery datepicker has beforeShowDay, so now you can have all the dates that are available in your database in an Array, then override beforeShowDay method while initializing the datepicker, check if the selected date is in the array or not, if not return else proceed.

Look here for code sample

Community
  • 1
  • 1
mprabhat
  • 20,107
  • 7
  • 46
  • 63
  • I think OP potentially has a list of dates rather than a range. i.e with some dates unavailable in between. I could be wrong though – musefan Apr 13 '12 at 14:38
0

You may try jQuery UI Datepicker

The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages. You can customize the date format and language, restrict the selectable date ranges and add in buttons and other navigation options easily.

Alfred
  • 21,058
  • 61
  • 167
  • 249