maxDate and minDate not working in Jquery Datetime picker - javascript

All other attributes like format ,autoclose etc are working, but maxDate/minDate is not working.
Any help would be appreciated.
I am using bootstrap-datetimepicker
$(function() {
$("#fdate").datetimepicker({
format: 'yyyy-mm-dd',
pickTime: false,
startView: 'month',
minView: 'month',
autoclose: true,
maxDate: '0'
});
});

Isn't it suppose to be a date value. And also it seems you forgot to use the option in it.
$("#datepicker").datepicker('option', {minDate: <some date>, maxDate: <some date>});
Please have a look here.

-> At first see that have you imported the correct path for bootstrap-datetimepicker
$('#date').datepicker('option', { minDate: new Date(startDate), maxDate: new Date(endDate) });

Thanks to Nargis ,Rajesh & sibeesh for your Quick replies..
I Solved the problem ..
The problem was maxDate and minDate are attributes used in some other plugin (i think jquery datatime picker) . as I am using an old Bootstrap plugin ,The valid attributes are startDate and endDate
The worked code is below
$(function() {
$( "#fdate" ).datetimepicker(
{
format: 'yyyy-mm-dd',
pickTime: false,
startView: 'month',
minView: 'month',
autoclose: true,
startDate: '-1d',//previous date
endDate: new Date()//current date
});
});

Related

Disable future dates after today in Jquery Ui1.8.9 [duplicate]

Is it possible to disable future date from today?
Let say today is 23/10/2010, so 24/10/2010 onwards are disabled.
Sorry I am very new in jQuery and JavaScript.
Yes, indeed. The datepicker has the maxdate property that you can set when you initialize it.
Here's the codez
$("#datepicker").datepicker({ maxDate: new Date, minDate: new Date(2007, 6, 12) });
$(function() { $("#datepicker").datepicker({ maxDate: '0'}); });
Try This:
$('#datepicker').datepicker({
endDate: new Date()
});
It will disable the future date.
you can use the following.
$("#selector").datepicker({
maxDate: 0
});
Code for Future Date only with disable today's date.
var d = new Date();
$("#delivdate").datepicker({
showOn: "button",
buttonImage: base_url+"images/cal.png",
minDate:new Date(d.setDate(d.getDate() + 1)),
buttonImageOnly: true
});
$('.ui-datepicker-trigger').attr('title','');
Date for the future 1 year can be done by
$('.date').datepicker({dateFormat: 'yy-mm-dd', minDate:(0), maxDate:(365)});
you can change the date format too by the parameter dateFormat
http://stefangabos.ro/jquery/zebra-datepicker
use zebra date pickers:
$('#select_month1').Zebra_DatePicker({
direction: false,
format: 'Y-m-d',
pair: $('#select_month2')
});
$('#select_month2').Zebra_DatePicker({
direction: 1, format: 'Y-m-d',
});
Yes, datepicker supports max date property.
$("#datepickeraddcustomer").datepicker({
dateFormat: "yy-mm-dd",
maxDate: new Date()
});
$('#thedate,#dateid').datepicker({
changeMonth:true,
changeYear:true,
yearRange:"-100:+0",
dateFormat:"dd/mm/yy" ,
maxDate: '0',
});
});

How to set plus two years in daterangepicker jquery

I have two daterangepicker, I want to set plus two year as the maxdate for the second daterangepicker based on the value from first daterangepicker. For example if I set the value to "2019-10-10" on the first daterangepicker then the maxdate should be set to the second datepicker as "2021-10-10".
This is what I have tried but not seems to be working
$('.date-select').daterangepicker({
singleDatePicker: true,
locale: {
format: 'YYYY-MM-DD'
},
}).on("input change", function (e) {
$("#end_date").daterangepicker({ singleDatePicker: true, minDate: -0,dateFormat: 'YYYY-MM-DD', maxDate: "+0D+0M+2Y" });
});
$('#end_date').daterangepicker({
singleDatePicker: true,
locale: {
format: 'YYYY-MM-DD'
},
});
}
});
It shows invalid date. Help is much appreciated. Thanks.
I don't see you referencing the first date input at all. Try fetching it's value, convert it to a Date object, add two years and set it as the new maxDate of the #end_date input like so:
$('#start_date').daterangepicker({
singleDatePicker: true,
locale: {
format: 'YYYY-MM-DD'
},
}).on("input change", function (e) {
let d = new Date( $('#start_date').val() );
d.setFullYear(d.getFullYear() + 2);
$('#end_date').daterangepicker({
singleDatePicker: true, locale: {format: 'YYYY-MM-DD'}, maxDate: d
});
});
$('#end_date').daterangepicker({
singleDatePicker: true, locale: {format: 'YYYY-MM-DD'},
});
See this JS Bin for a demo.
By the way: you might have your reasons to choose otherwise, but it would be much easier if you don't use two seperate inputs and define maxSpan option. That way, you don't have to deal with events at all and the library does the work for you.
You can also use 'OnSelect' event of Datepicker for the same...
$("#From_Date").datepicker({
dateFormat: 'dd/mm/yy',
onSelect: function(dateStr) {
var d = $.datepicker.parseDate('dd/mm/yy', dateStr);
var years = parseInt(2);
d.setFullYear(d.getFullYear() + years);
$('#To_Date').datepicker('setDate', d);
}
});
$("#To_Date").datepicker({
dateFormat: 'dd/mm/yy'
});
this is html for it.
<input id="From_Date" />
<input id="To_Date" />

how can i open auto datepicker range departure

sorry my question maybe is too esay but i am not understand javascript. i have a range datepicker. arrival-departure. i want to when i selected arrival auto open departure picker. here is my js code.
$('#arrival').datetimepicker({
useCurrent: false,
format: 'DD/MM/YYYY',
minDate: 'now'
});
$('#departure').datetimepicker({
useCurrent: false,
format: 'DD/MM/YYYY',
minDate: 'now'
});
$("#arrival").on("change.datetimepicker", function (e) {
$('#departure').datetimepicker('minDate', e.date);
});
$("#departure").on("change.datetimepicker", function (e) {
$('#arrival').datetimepicker('maxDate', e.date);
});
You can use the onShow() callback with setOptions() to set the min and max dates on the datetimepicker on the fly.
A few other things I noticed:
e.date is undefined so I used the .val() of the date time picker for the dates.
Also your format was off you are doubling month names and days and quadrupling years. So I set it to format 04/May/2018 format in the below example.
I also set the max date on the arrival picker (to the departure time) if the departure is set, otherwise there is now max.
$('#arrival').datetimepicker({
useCurrent: false,
format: 'd/M/Y',
onShow: function(ct) {
this.setOptions({
minDate: "now",
maxDate: $('#departure').val() ? new Date($('#departure').val()) : false
})
}
});
$('#departure').datetimepicker({
useCurrent: false,
format: 'd/M/Y',
onShow: function(ct) {
this.setOptions({
minDate: new Date($('#arrival').val())
})
}
});
$("#arrival").on("change.datetimepicker", function(e) {
$('#departure').datetimepicker("show");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js"></script>
arrive <input id="arrival" type="text">
depart <input id="departure" type="text">

Format date of JQuery Datepicker [duplicate]

I use the datepicker from jQuery UI, but the format is like example today: 08/01/2013
But i want the format to be example today: 2013-08-01
Here is code line i think maybe i should use?
`$( "#txtFromDate" ).datepicker( "option", "dateFormat", "yyyy-mm-dd" );`
And here is my jQuery code i use that works fine but don't know where to put the line?
And i want the format in both of my fields.
`
$(document).ready(function(){
$("#txtFromDate").datepicker({
minDate: "07/17/2012",
maxDate: "0D",
numberOfMonths: 2,
onSelect: function(selected) {
$("#txtToDate").datepicker("option","minDate", selected);
}
});
$("#txtToDate").datepicker({
minDate: "07/17/2013",
maxDate:"0D",
numberOfMonths: 2,
onSelect: function(selected) {
$("#txtFromDate").datepicker("option","maxDate", selected);
}
});
});`
I hope somebody have a solution for this :-)
since your already have other options in the datepicker... add it there.
try this
$("#txtFromDate").datepicker({
minDate: "07/17/2012",
maxDate: "0D",
numberOfMonths: 2,
dateFormat: "yy-mm-dd", //<----here
onSelect: function(selected) {
$("#txtToDate").datepicker("option","minDate", selected);
}
});
You can directly set the date format from jquery-ui library,that's work for me.hope for you also
in
function Datepicker()
{
//other code
dateFormat: "yy-mm-dd", // See format options on parseDate
//other code
}

Disable future dates after today in Jquery Ui Datepicker

I want to disable all the future dates after today in Jquery Ui Datepicker
Here is the Demo :
Code :
$( "#start_date" ).datepicker(
{
maxDate: '0',
beforeShow : function()
{
jQuery( this ).datepicker('option','maxDate', jQuery('#end_date').val() );
},
altFormat: "dd/mm/yy",
dateFormat: 'dd/mm/yy'
}
);
$( "#end_date" ).datepicker(
{
maxDate: '0',
beforeShow : function()
{
jQuery( this ).datepicker('option','minDate', jQuery('#start_date').val() );
} ,
altFormat: "dd/mm/yy",
dateFormat: 'dd/mm/yy'
}
);
Try this
$(function() {
$( "#datepicker" ).datepicker({ maxDate: new Date() });
});
Or you can achieve this using as below:
$(function() {
$( "#datepicker" ).datepicker({ maxDate: 0 });
});
Reference
DEMO
UPDATED ANSWER
This worked for me endDate: "today"
$('#datepicker').datepicker({
format: "dd/mm/yyyy",
autoclose: true,
orientation: "top",
endDate: "today"
});
SOURCE
In my case, I have given this attribute to the input tag
data-date-start-date="0d"
data-date-end-date="0d"
You can simply do this
$(function() {
$( "#datepicker" ).datepicker({ maxDate: new Date });
});
JSFiddle
FYI: while checking the documentation, found that it also accepts numeric values too.
Number: A number of days from today. For example 2 represents two days
from today and -1 represents yesterday.
so 0 represents today. Therefore you can do this too
$( "#datepicker" ).datepicker({ maxDate: 0 });
Change maxDate to current date
maxDate: new Date()
It will set current date as maximum value.
In case you are appending Dtpicker,use the following code
$('#enddate').appendDtpicker({
"dateOnly": true,
"dateFormat": "YYYY-MM-DD",
"closeOnSelected": true,
maxDate: new Date()
});
//Disable future dates after current date
$("#datepicker").datepicker('setEndDate', new Date());
//Disable past dates after current date
$("#datepicker").datepicker('setEndDate', new Date());
Datepicker does not have a maxDate as an option. I used this endDate option. It worked well.
$('.demo-calendar-default').datepicker({
autoHide: true,
zIndex: 2048,
format: 'dd/mm/yyyy',
endDate: new Date()
});
maxDate: new Date()
its working fine for me disable with current date in date range picker

Categories

Resources