2
  • I have one datepicker with numberOfMonths set to 2.
  • Arrival Date and Departure Date are determined using this logic (within onSelect):

if ((count % 2)==0) {
      depart = $("#datepicker-1").datepicker('getDate');
      if (arriv > depart) { temp=arriv; arriv=depart; depart=temp; }
      $("#check-in").val($.datepicker.formatDate("DD, MM d, yy",arriv)); 
      $("#check-out").val($.datepicker.formatDate("DD, MM d, yy",depart));
     } else {
      arriv = $("#datepicker-1").datepicker('getDate');
      depart = null;
      if ((arriv > depart)&&(depart!=null)) { temp=arriv; arriv=depart; depart=temp; }
      $("#day-count").val('');
      $("#check-in").val($.datepicker.formatDate("DD, MM d, yy",arriv));
      $("#check-out").val($.datepicker.formatDate("DD, MM d, yy",depart));
     }

     if(depart!=null) { 
      diffDays = Math.abs((arriv.getTime() - depart.getTime())/(oneDay)); 
      if (diffDays == 0) { $("#day-count").val((diffDays+1)+' Night/s'); } else { $("#day-count").val(diffDays+' Night/s'); }
     }
  • Getting the number of days within these 2 dates has no problem
  • What I want now is highlight those dates starting from the Arrival to Departure
  • I tried working around the onSelect but had no luck.
  • I am now using beforeShowDay to highlight these dates but I can't seem to figure it out
  • Got a sample from here
  • Basically, it is customized to highlight 11 or 12 days after the selected date (Here's the code from that link).
    $('#datePicker').datepicker({beforeShowDay: function(date) {
                        if (selected != null && date.getTime() > selected.getTime() &&
                            (date.getTime() - selected.getTime()) 
  • Since I am new to using the UI, and the logic is not clear to me yet, I can't seem to figure this out. Any ideas on how I can make this highlight dates between the Arrival and Departure using my aforementioned logic used in determining the two?
2
  • You mean to highlight it in the Jquery UI's calender pop-up...? Commented Apr 16, 2010 at 9:30
  • What do you mean calendar pop-up? Basically, I want to highlight the dates starting from the first selected date up to the second selected date. For example, I selected Apr 19 2010 and ended my selection at Apr 21. The dates from Apr 19 should highlight (or change its background color to something) up to Apr 21 2010. Commented Apr 19, 2010 at 2:47

3 Answers 3

4

Super old question but I came across the answer for anyone that finds this: http://jsfiddle.net/kVsbq/4/

JS

$(".datepicker").datepicker({
minDate: 0,
numberOfMonths: [12, 1],
beforeShowDay: function (date) {
    var date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input1").val());
    var date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input2").val());
    return [true, date1 && ((date.getTime() == date1.getTime()) || (date2 && date >= date1 && date <= date2)) ? "dp-highlight" : ""];
},
onSelect: function (dateText, inst) {
    var date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input1").val());
    var date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input2").val());
    if (!date1 || date2) {
        $("#input1").val(dateText);
        $("#input2").val("");
        $(this).datepicker();
    } else {
        $("#input2").val(dateText);
        $(this).datepicker();
    }
}
});
Sign up to request clarification or add additional context in comments.

Comments

1

IF this helps.. :-)

$(function() {
     var togo=['10/25/2013']
     var datesArray=['10/27/2013','10/28/2013']
     var datesArray1=['10/25/2013','10/26/2013']
     var datesArray2=['10/24/2013']


        $( "#datepicker" ).datepicker({
            numberOfMonths: 2,

            selectMultiple:true,
            beforeShowDay: function (date) {
                var theday = (date.getMonth()+1) +'/'+ 
                            date.getDate()+ '/' + 
                            date.getFullYear();
                    return [true,$.inArray(theday, datesArray2) >=0?"specialDate":($.inArray(theday, datesArray)>=0?"specialDate2":($.inArray(theday, datesArray1)>=0?"specialDate1":''))];
                },

            onSelect: function(date){

             console.log("clicked"+date);  
            return [true,$.inArray(['10/24/2013'], togo) >=0?"specialDate":($.inArray(date, datesArray1)>=0?"specialDate1":'')] ;  

            }

        });
        //$.inArray(theday, datesArray) >=0?"specialDate":'specialDate1'
    });

http://jsfiddle.net/pratik24/Kyt2w/3/

Comments

0

Not quite an answer, but this may be useful:

http://www.eyecon.ro/datepicker/

Rather unfortunately named, but it seems like it could be what you need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.