41

I want to disable all the future dates after today in Jquery Ui Datepicker

Here is the Demo :

Code :

$( "#start_date" ).datepicker(

        { 
            maxDate: '0', 
            beforeShow : function()
            {
                jQuery( this ).datepicker('option','maxDate', jQuery('#end_date').val() );
            },
            altFormat: "dd/mm/yy", 
            dateFormat: 'dd/mm/yy'

        }

);

$( "#end_date" ).datepicker( 

        {
            maxDate: '0', 
            beforeShow : function()
            {
                jQuery( this ).datepicker('option','minDate', jQuery('#start_date').val() );
            } , 
            altFormat: "dd/mm/yy", 
            dateFormat: 'dd/mm/yy'

        }

);
itzmebibin
  • 9,199
  • 8
  • 48
  • 62
Hassan Sardar
  • 4,413
  • 17
  • 56
  • 92
  • 2
    possible duplicate of [Disable future dates in jQuery UI Datepicker](http://stackoverflow.com/questions/4002781/disable-future-dates-in-jquery-ui-datepicker) – Pekka Mar 04 '14 at 05:28

9 Answers9

95

Try this

 $(function() {
  $( "#datepicker" ).datepicker({  maxDate: new Date() });
 });

Or you can achieve this using as below:

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

Reference

DEMO

UPDATED ANSWER

Amit
  • 15,217
  • 8
  • 46
  • 68
19

This worked for me endDate: "today"

  $('#datepicker').datepicker({
        format: "dd/mm/yyyy",
        autoclose: true,
        orientation: "top",
        endDate: "today"

  });

SOURCE

9

In my case, I have given this attribute to the input tag

data-date-start-date="0d" data-date-end-date="0d"

Megamind
  • 99
  • 1
  • 1
  • This should be preferred if you have a generic JS code for all datepickers and out of those you need to restrict date in one or two fields. – dipak_pusti May 25 '21 at 02:45
7

You can simply do this

$(function() {
    $( "#datepicker" ).datepicker({  maxDate: new Date });
  });

JSFiddle

FYI: while checking the documentation, found that it also accepts numeric values too.

Number: A number of days from today. For example 2 represents two days from today and -1 represents yesterday.

so 0 represents today. Therefore you can do this too

 $( "#datepicker" ).datepicker({  maxDate: 0 });
Praveen
  • 55,303
  • 33
  • 133
  • 164
3

Change maxDate to current date

maxDate: new Date()

It will set current date as maximum value.

Mohit Pandey
  • 3,679
  • 7
  • 26
  • 38
2

In case you are appending Dtpicker,use the following code

$('#enddate').appendDtpicker({
    "dateOnly": true,
    "dateFormat": "YYYY-MM-DD",
    "closeOnSelected": true,
    maxDate: new Date()         
});
Kalamarico
  • 5,466
  • 22
  • 53
  • 70
burningEye
  • 29
  • 7
1

Datepicker does not have a maxDate as an option. I used this endDate option. It worked well.

$('.demo-calendar-default').datepicker({
  autoHide: true,
  zIndex: 2048,
  format: 'dd/mm/yyyy',
  endDate: new Date()
});
Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
1

//Disable future dates after current date

$("#datepicker").datepicker('setEndDate', new Date());

//Disable past dates after current date

$("#datepicker").datepicker('setEndDate', new Date());
Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
-4
maxDate: new Date() 

its working fine for me disable with current date in date range picker

Dhia
  • 10,119
  • 11
  • 58
  • 69
rupank
  • 7
  • 2