Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI: DatePicker, select only today's date through past

I'm using the datePicker in the jQuery UI core. I need a date picker that can only pick dates through the past all the way to today.

Is there an easy way to do this? -- Note I'm using the UI core, not the DatePicker Plugin.

My jQuery call:

$(function() {
    $(".datepicker").datepicker();
});
like image 583
Snow_Mac Avatar asked May 17 '11 15:05

Snow_Mac


People also ask

How set today's date in jQuery datepicker?

Set Current Date in DatePicker using jQueryvar now = new Date(); var day = ("0" + now. getDate()).

How can change date format in jQuery ui datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How do I turn off past dates on calendar?

How do I turn off past date in calendar? the previous dates we need to set the minDate property of the date picker. if we set minDate:0 then it will disable all the previous dates. and we set input attribute min:current_date then it will disable all the previous dates.

How to use jQuery UI datepicker?

The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.


1 Answers

You should use the maxDate option when initializing the datepicker:

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

look here for reference: http://jqueryui.com/demos/datepicker/#option-maxDate

like image 51
Nicola Peluchetti Avatar answered Sep 24 '22 15:09

Nicola Peluchetti