Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set yesterday date in DatePicker using Jquery

I'm having a textbox, when user click on it calender appears.This works fine,the calender showing the current date and previous date all are disable.But now i want to show calender with yesterday date selected.How can i achieve this.

for eg: if current date is 19-July-2012 then the calender must show date from 18-july-2012 and all other date before 18th must be inactive.how can I do that ?

Thanks in advance.

like image 400
Rakesh Shetty Avatar asked Nov 30 '25 10:11

Rakesh Shetty


2 Answers

Visit the documentation: http://docs.jquery.com/UI/Datepicker#option-defaultDate

$( ".yourselector" ).datepicker({ defaultDate: -1, minDate:'-1d' });
like image 61
Sangar82 Avatar answered Dec 02 '25 00:12

Sangar82


To have yesterday selected, you can do:

$( ".selector" ).datepicker({ defaultDate: -1 });

See http://jqueryui.com/demos/datepicker/#option-defaultDate for the details.

Edit:

Based on the comment, the DatePicker should show dates from yesterday. So this requires a minDate of yesterday.

    $(".selector").datepicker({minDate: -1});

See: http://jsfiddle.net/E3VEm/1/

like image 20
stephangroen Avatar answered Dec 02 '25 01:12

stephangroen