Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery DatePicker with today as maxDate

I would like to set today's date as a maxdate for jQuery datepicker in order to prevent users from picking date greater than today's date

like image 959
Emmanuel N Avatar asked Oct 28 '11 19:10

Emmanuel N


People also ask

How to restrict date in jQuery Datepicker?

When Start Date is selected, then need to disable all the dates before selected start date + 4 days in end date datepicker. "minDate" option is our choice here. If end date is selected first, then disable all the dates after selected end date - 4 days in Start date datepicker. "maxDate" option is our choice here.

What is minDate and maxDate in jQuery Datepicker?

If you like to restrict access of users to select a date within a range then there is minDate and maxDate options are available in jQuery UI. Using this you can set the date range of the Datepicker. After defining these options the other days will be disabled which are not in a defined range.

How can I get current date in Datepicker?

To set current date in control to which jQuery UI datepicker bind, use setDate() method. Pass date object which needs to be set as an argument to setDate() method. If you want to set it to current date then you can pass 'today' as argument.

How do I change date format in Datepicker?

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


2 Answers

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

This will set the maxDate to +0 days from the current date (i.e. today). See:

http://api.jqueryui.com/datepicker/#option-maxDate

like image 137
Alex Peattie Avatar answered Sep 21 '22 13:09

Alex Peattie


http://api.jqueryui.com/datepicker/#option-maxDate

$( ".selector" ).datepicker( "option", "maxDate", '+0m +0w' ); 
like image 45
Smamatti Avatar answered Sep 22 '22 13:09

Smamatti