77

Is it possible to disable future date from today?

Let say today is 23/10/2010, so 24/10/2010 onwards are disabled.

Sorry I am very new in jQuery and JavaScript.

9 Answers 9

128

Yes, indeed. The datepicker has the maxdate property that you can set when you initialize it.

Here's the codez

$("#datepicker").datepicker({ maxDate: new Date, minDate: new Date(2007, 6, 12) });
1
  • 5
    Remember that when setting javascript's Date object use month-1. So, Jan is 0 and Dec is 11. This just slipped my mind for a few minutes.
    – mawburn
    Aug 22, 2013 at 19:38
38
$(function() { $("#datepicker").datepicker({  maxDate: '0'}); });
2
  • 3
    We can use with out single quotes also for ex: maxDate: 0
    – RajeshKdev
    Apr 29, 2013 at 5:52
  • 5
    nice. I needed this for Date of Death. End user kept predicting the death of people. Nov 4, 2015 at 16:02
14

Try This:

$('#datepicker').datepicker({
    endDate: new Date()
});

It will disable the future date.

1
  • 3
    endDate works, maxDate doesn't work for me, thanks @pankaj
    – bdalina
    Mar 20, 2019 at 3:48
4

you can use the following.

$("#selector").datepicker({
    maxDate: 0
});
3

Code for Future Date only with disable today's date.

 var d = new Date();
         $("#delivdate").datepicker({
         showOn: "button",
         buttonImage: base_url+"images/cal.png",
         minDate:new Date(d.setDate(d.getDate() + 1)),
         buttonImageOnly: true
        });
         $('.ui-datepicker-trigger').attr('title',''); 
1
  • 4
    Welcome to Stack Overflow! please avoid putting words in Caps and bold unless they are very important.
    – Unni Kris
    Nov 9, 2012 at 7:15
3

Date for the future 1 year can be done by

$('.date').datepicker({dateFormat: 'yy-mm-dd', minDate:(0), maxDate:(365)});

you can change the date format too by the parameter dateFormat

1
  • 1
    link can be visited for further datepicker parameters. Oct 28, 2013 at 11:00
0

http://stefangabos.ro/jquery/zebra-datepicker

use zebra date pickers:

$('#select_month1').Zebra_DatePicker({
  direction: false,
  format: 'Y-m-d',
  pair: $('#select_month2')
});

$('#select_month2').Zebra_DatePicker({
  direction: 1, format: 'Y-m-d',
});
0

Yes, datepicker supports max date property.

 $("#datepickeraddcustomer").datepicker({  
             dateFormat: "yy-mm-dd",  
             maxDate: new Date()  
        });
1
  • How is your answer different than the currently accepted one?
    – Wtower
    Dec 12, 2015 at 7:08
-2
$('#thedate,#dateid').datepicker({
     changeMonth:true,
         changeYear:true,
         yearRange:"-100:+0",
         dateFormat:"dd/mm/yy" ,
         maxDate: '0',
     });
});
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.