13

I am making a hotel reservation system i have to disable past dates in jQuery UI datepicker here's the code

calling in .cs

   public class CheckLookup
        {
            [DataType(DataType.Date)]
            public DateTime checkindate { get; set; }
            [DataType(DataType.Date)]
            public DateTime checkoutdate { get; set; }
        }

Here's the javascript

 $(document).ready(function () {
        function getDateYymmdd(value) {
            if (value == null)
                return null;
            return $.datepicker.parseDate("yy-mm-dd", value);
        }
        $('.date').each(function () {
            var minDdate = getDateYymmdd($(this).data(""));
            var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
            $(this).datepicker({
                dateFormat: "dd-mm-yy", 
                minDate: minDate,
                maxDate: maxDate
            });
        });
    });

tell me the modification to be done in this code.

0

1 Answer 1

32

You can try this:

$('.date').datepicker({ minDate: 0 });

for you case:

$('.date').each(function () {
   var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
   $(this).datepicker({
         dateFormat: "dd-mm-yy", 
         minDate: 0,
         maxDate: maxDate
   });
});
Sign up to request clarification or add additional context in comments.

3 Comments

Its working great man but formet is changing automaticly from dd-mm-yy to mm-dd-yy
@SahilPopli I think dateFormat should not change, see here jsbin.com/ecome/25/edit
hey i have done it i need one more favor i want that if i set checkin date 20-08-2012 the 2nd date picker set from 21-8-2012 how to do this tell plz

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.