Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set minDate to current date in jQuery UI Datepicker?

This is my code and it is not working correctly. I want to set minDate to the current date. How can I do it?

$("input.DateFrom").datepicker({     changeMonth: true,      changeYear: true,      dateFormat: 'yy-mm-dd',     maxDate: 'today',     onSelect: function(dateText) {         $sD = new Date(dateText);         $("input#DateTo").datepicker('option', 'minDate', min);     } 
like image 686
Ejaz Karim Avatar asked Feb 11 '13 10:02

Ejaz Karim


People also ask

How can I select 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 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 you set minDate on DateTimePicker?

Step 1: Create a DateTimePicker using the DateTimePicker() constructor is provided by the DateTimePicker class. // Creating a DateTimePicker DateTimePicker dt = new DateTimePicker(); Step 2: After creating DateTimePicker, set the MinDate property of the DateTimePicker provided by the DateTimePicker class.


2 Answers

You can specify minDate as today by adding minDate: 0 to the options.

$("input.DateFrom").datepicker({     minDate: 0,     ... }); 

Demo: http://jsfiddle.net/2CZtV/

Docs: http://jqueryui.com/datepicker/#min-max

like image 56
techfoobar Avatar answered Sep 16 '22 15:09

techfoobar


You can use the minDate property, like this:

$("input.DateFrom").datepicker({     changeMonth: true,      changeYear: true,      dateFormat: 'yy-mm-dd',     minDate: 0, // 0 days offset = today     maxDate: 'today',     onSelect: function(dateText) {         $sD = new Date(dateText);         $("input#DateTo").datepicker('option', 'minDate', min);     } }); 

You can also specify a date, like this:

minDate: new Date(), // = today 
like image 27
Rory McCrossan Avatar answered Sep 20 '22 15:09

Rory McCrossan