I use bootstrap datepicker when i try to call the date function it's not working can anyone help me please.
var date ="1/3/2015";
$( '.input-daterange .from-date' ).datepicker( {
autoclose:true,
endDate : new Date(date),
format: "mm/dd/yyyy",
} );
date =(dat.getMonth()+1) +"/" +dat.getDate() + "/"+ dat.getFullYear();
$( '.input-daterange .from-date' ).click(function(){
$( '.input-daterange .from-date' ).datepicker('update');
});
Onload it works fine with this date "1/3/2015" afterwards trying the update the variable date with current-date it's not working.
This should work:
$('.from-date').datepicker("setDate", new Date(2008,9,03) );
You have to put there data object like on an example
This works for me:
$( '.input-daterange .from-date' ).datepicker('update',new Date());
Related
How can I change the setting of one datepicker inside of other datepicker?
This is what I tried
$('#from_date').datepicker({
autoclose:true,
}).on('changeDate', function() {
$('#to_date').datepicker({
minDate: $('#from_date').val(),
});
});
I also tried this
$('#from_date').datepicker({
autoclose:true,
}).on('changeDate', function() {
$('#to_date').datepicker('option', 'minDate', $('#from_date').val())
});
I want to disable the date before the from_date value if the from_date date is changed.
Thanks for the help
Try setStartDate method
Note: jquery-ui-datepicker and bootstrap-datepicker are different
$('#from_date').datepicker({
autoclose:true,
}).on('changeDate', function(e) {
$('#to_date').datepicker('setStartDate', e.date)
});
You should use the option api.
Use it like this:
example:
$( ".selector" ).datepicker( "option", "disabled", true );
With your code:
$('#to_date').datepicker( "option", "minDate", $('#from_date').val())
I have datepicker codes below to display me calendar, the current date is selected by default, i would like to select the previous date by default instead (the day before today). I have tried but i failed anybody can help me please?
$(function() {
$("#datepicker").datepicker({ dateFormat: "yy-mm-dd" }).val()
});
I finally resolved my issue this way
$(function() {
$("#datepicker").datepicker({ dateFormat: "yy-mm-dd" }).val();
$("#datepicker").click(function() {
date = new Date();
date.setDate(date.getDate()-1);
$( "#datepicker" ).datepicker( "setDate" , date);
});
});
Try this:
$(".datepicker").datepicker("setDate", -1)
More info: http://api.jqueryui.com/datepicker/#method-setDate
I am not able to set the startDate parameter to a datePicker.
I was trying to look for a solution and came up with nothing that works.
What i need is to set default value to the datePicker (1/1/1970) and when I click it I want it to show me the date of today.
This is what I came up with, although it's not working:
$(".from-date").datepicker( "setDate" , "1/1/1970" );
$(".from-date").datepicker("option", { startDate: "1/1/2015" } );
What am I doing wrong?
Use this Demo here
$('.datepicker').datepicker();
$('.datepicker').datepicker('setDate', '1/1/1970');
$('.datepicker').click(function(){
var myDate = new Date() ;
$('.datepicker').datepicker('setDate', myDate);
});
You should set your date first as default date and on textbox selection fire jquery for change default date of datepicker and set today's date as default date
$('.datepicker').datepicker();
$('.datepicker').datepicker('setDate', '1/1/1970');
$('.datepicker').click(function(){
var myDate = new Date() ;
$('.datepicker').datepicker('setDate', myDate);
});
Here Is Fiddle
You can put a minDate in the datePicker that will disable all the dates before this minDate.
Find the Fiddle
$(function() {
var todayDate = new Date();
//$('.datepicker').datepicker();
$( ".datepicker" ).datepicker({
minDate:"01/01/1970"
});
$( ".datepicker" ).datepicker("setDate", todayDate);
});
I have two date pickers. A startdate and an enddate.
The way I have the code set up is that the second datepicker won't be initiated until the first one has been changed. The enddate datepicker is initialized with the current date on startdate. The only problem is that if you change the time on the first datepicker it doesn't refresh the mindate on enddate.
$(function(){
$( "#startdate" ).datepicker({ minDate: currentTime });
//When the startdate changes change the mindate for the enddate picker
$( "#startdate" ).change(function (){
startTime = ($("#startdate").val());
$("#enddate").datepicker({ minDate: startTime });
});
//$( "#enddate" ).datepicker({ minDate: currentTime });
});
You will need to use the option method as described in the documentation (http://jqueryui.com/demos/datepicker/#method-option) to update the minDate option of an already initialized widget:
$( "#startdate, #enddate" ).datepicker({ minDate: currentTime });
$('#startdate').change(function () {
var startTime = ($("#startdate").val());
$("#enddate").datepicker('option', 'minDate', startTime);
});
Notice I put a var statement in-front of the startTime variable so it will be declared in the local scope of the event handler. Also both Datepickers get initialized strait-off and then the #enddate widget gets an updated minDate option each time the #startdate element is changed.
Here is a demo: http://jsfiddle.net/VP25m/
EDIT: Try using the refresh() function on datepicker:
$( "#startdate" ).change(function (){
startTime = ($("#startdate").val());
$("#enddate").datepicker({ minDate: startTime });
$("#enddate").datepicker('refresh');
});
OLD ANSWER BELOW:
You will probably want to set the end date datepicker to a variable so you can destroy and re-initialize it when the start date changes.
$( "#startdate" ).change(function (){
startTime = ($("#startdate").val());
if($("#enddate").datepicker("enabled")) {
endDatePicker.datepicker( "destroy" );
}
var endDatePicker = $("#enddate").datepicker({ minDate: startTime });
});
Use datepicker's onSelect event instead of change event of textbox. In this event you get the selected date as the first argument which you can use to set as minDate of enddate datapicker.
$( "#startdate" ).datepicker({
minDate: currentTime,
onSelect: function(date){
//if the datepicker is not initialized
$("#enddate").datepicker({ minDate: date });
//if the datepicker is already initialized
$("#enddate").datepicker("option", "minDate", date);
}
});
Demo
Reference: http://jqueryui.com/demos/datepicker/#event-onSelect
I have tried mindate:0 but it is not working for my code.I have tried for the solutions on stack overflow but unable to adapt it to my code.I wish to disable the past dates on the datepicker. Kindly help me .This is my code:-
<script>
$(document).ready(function() {
$("#departing").datepicker({onSelect: function() {
var selectedDate = $(this).datepicker( 'getDate' );
}
});
});
</script>
I think it may help you. Please try this code
<script>
$(document).ready(function() {
var dateToday = new Date();
$("#departing").datepicker({
minDate: dateToday,
onSelect: function() {
var selectedDate = $(this).datepicker( 'getDate' );
}
});
});
</script>