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>
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] .
inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });
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.
$('#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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With