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);
});
Related
How can I dynamically set the datepicker's date value in Bootstrap?
});
$('.datepicker').datepicker();
$('#datetimepicker1').datetimepicker({
date: $('#datetimepicker1 input').val(),
format : "YYYY-MM-DD HH:mm:ss",
}).on('dp.change', function(ev){
$('#datetimepicker1 input').val(ev.date)
});
// $('.selectpicker').selectpicker('hide');
});
try this code:
$(".datepicker").datepicker("update", new Date());
I am using a plugin on woocommerce and I need to disable sundays and some specific dates (Xmas holidays) on date picker. Your help is much appreciated.
I have managed to disable the today date but I am struggling to do the rest.
Also is there a way of adding a if statement that if time is > 17:00 automatically datepicker changes to +2 days and else just +1?
(function( $ ) { $(function() {
if ($('.pcfme-datepicker').length) {
$('.pcfme-datepicker').datepicker({
dateFormat : 'dd-mm-yy'
});
}
var dateToday = new Date();
dateToday.setDate(dateToday.getDate() + 1);
if ($('.pcfme-datepicker-disable-past').length) {
$('.pcfme-datepicker-disable-past').datepicker({
dateFormat : 'dd-mm-yy',
minDate: dateToday
});
}
});
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 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());
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