Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery ui 1.7.3 datepicker set selected date + 3 days

How can I set a selected date of the jquery datepicker by adding 3 days to the actual date?

Like from 11/01/2011 to 11/04/2011

My current code doesn't work!

<script type="text/javascript">
        $(function() {$("#datepicker").datepicker();});
        //Set DatePicker to actual date + 3 days
        $('#dateselector').datepicker("setDate", new Date(date.getMonth()+"/"+(date.getDate()+3)+"/"+date.getFullYear()) );                      
</script>
like image 310
burner007 Avatar asked Nov 15 '11 16:11

burner007


People also ask

How do I highlight specific dates in jQuery ui datepicker?

Define beforeShowDay within datepicker() method. In the function create a new date format according to the defined format (dd-mm-yyyy) in an Array. Check for the date in the Array with $. inArray() method if it is available then return [true, "highlight", tooltip_text]; otherwise return [true] .

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 restrict future dates in datepicker?

if we want to change the date format form yyyy-mm-dd to dd-mm-yyyy than we just simply update on format parameter. after applying this parameter we can easily disable future dates in our datepicker of web form.


1 Answers

$('#datepicker').datepicker("setDate", "+3");

Working example: http://jsfiddle.net/EryYr/1/

Quote from documentation:

setDate .datepicker( "setDate" , date ) ... The new date may be a Date object or a string in the current date format (e.g. '01/26/2009'), a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null to clear the selected date.

like image 52
yko Avatar answered Oct 22 '22 23:10

yko