Bootstrap datepicker how to allow past 6 months dates - javascript

How can I enable past 6 months dates from today including today in Bootstrap datepicke.
For example if today is 4th October 2015 then calendar will only allow to pick any date between 4th April 2015 to 4th October 2015.
var date = new Date();
// initialize daterange
$('.input-daterange').datepicker({
format: "mm/dd/yy",
orientation: "top left",
autoclose: true,
todayHighlight: false,
toggleActive: false,
startDate: date
});

startDate should do it (doc)

I'm asuming you are using this, so you can make use of endDate and startDate.
You need to set the startDate to the Date.now - 6 months and the endDate to today.
var now = new Date();
var sixmonthsago = new Date(now.setMonth(now.getMonth() - 6));
$('.input-daterange').datepicker({
format: "mm/dd/yy",
orientation: "top left",
autoclose: true,
todayHighlight: false,
toggleActive: false,
endDate: now,
startDate: sixmonthsago
});
I didint test the code.

Related

Allow the user to select only quarter month in jquery datepicker

How to limit Datepicker to allow the user to select only quarter month of the year
The Datepicker must allow the user to only select the quater month in future. Dates in the past must not be allowed.
Eg.if we are in jan then, in this case, quarter month should be enabled (march) and jan and feb should disable.
if we are in mar then in this case quater month should enabled(march) and jan and feb should disable.
if we are in Apr then in this case quater month should enabled(jun) and jan,feb,mar,apr,may should disable.
$(document).ready(function () {
$('.datepickerOne').datepicker({
format: "yyyy-mm",
viewMode: "months",
minViewMode: "months",
autoclose: true,
startDate: new Date(),
endDate: '+2y',
}).on("change", function () {
$("#testDetailsForm").bootstrapValidator('revalidateField', 'formsubmit_date');
})
});
try this
$(document).ready(function () {
$('.datepickerOne').datepicker({
format: "yyyy-mm",
viewMode: "months",
minViewMode: "months",
autoclose: true,
minDate:new Date(new Date().setMonth(new Date().getMonth() + 1)),
maxDate: "+2y"
}).on("change", function () {
$("#testDetailsForm").bootstrapValidator('revalidateField', 'formsubmit_date');
})
});
so try this. this Code Working as you say
$(document).ready(function () {
var currentTime = new Date();
// First Date Of the month
var startDateFrom = new Date(currentTime.getFullYear(),currentTime.getMonth(),1);
// Last Date Of the Month
var startDateTo = new Date(currentTime.getFullYear(),currentTime.getMonth() +2,1);
$('.datepickerOne').datepicker({
format: "yyyy-mm",
viewMode: "months",
minViewMode: "months",
autoclose: true,
minDate:startDateTo,
maxDate: "+2y"
}).
on("change", function () {
$("#testDetailsForm").bootstrapValidator('revalidateField', 'formsubmit_date');
})
});

foundation datepicker datesdisabled

I am trying to disable holidays in my calendar but can't seem to pass the right format to the datesdisabled option.
I have
$('#booking').fdatepicker({
var now = new Date();
$('#booking').fdatepicker({
format: 'dd MM yyyy',
startDate: now,
daysOfWeekDisabled: [0, 4, 5],
datesDisabled:['2018-02-13']
});
})
What am I missing?
Use it this way, as it doesn't support the way you are using it. Also, it doesn't support time, just date.
$(function(){
$('#dpt').fdatepicker({
initialDate: new Date(),
format: 'yyyy-mm-dd hh:ii',
disableDblClickSelection: true,
language: 'es',
pickTime: true,
datesDisabled:['2018-01-15']
});
});

Is it possible to customize the years range in bootstrap date picker

I have a attribute name is assessment year,in that attribute if i choose the year(ex 2012),the bootstrap date picker display the 2012 calendar only
my js file
$('.datepicker').datepicker({
format: "dd/mm/yyyy",
todayHighlight: true,
todayBtn: 'linked',
autoclose: true
});
I searched the lot of things,still i am not get a correct answer...help me friends
simple just add startDate and endDate assuming that you selected year "2016" http://jsfiddle.net/LcqM7/542/
$('.datepicker').datepicker({
autoclose: true,
startDate: '01/01/2016',
endDate: '12/31/2016'
});

How to disable date before today in datetimepicker bootstrap?

Demo and full code is like this : http://fiddle.jshell.net/oscar11/dgb09c5c/5/
My Javascript code is like this :
$('#time-start').datetimepicker({
format: 'yyyy-mm-dd hh:ii:ss',
autoclose: true,
pickerPosition: "bottom-left",
maxView: 3,
minuteStep: 1,
minDate: new Date()
})
How to disable date before today?
I add minDate: new Date(), but it's not working
Any solution to solve my problem?
From Bootstrap datetime picker documentation
$.fn.datetimepicker.defaults = {
maskInput: true, // disables the text input mask
pickDate: true, // disables the date picker
pickTime: true, // disables de time picker
pick12HourFormat: false, // enables the 12-hour format time picker
pickSeconds: true, // disables seconds in the time picker
startDate: -Infinity, // set a minimum date
endDate: Infinity // set a maximum date
};
I modified your Fiddle. Is it what you are looking for? http://fiddle.jshell.net/dgb09c5c/6/

Completely disabling dates out of the given range

I was using this plugin https://github.com/dangrossman/bootstrap-daterangepicker/ for a daterange picker. I want to completely disable/hide the dates that are out of the given start and end date range. Can some one help me with this please.
$('#datrange').daterangepicker({
timePicker: true,
timePickerIncrement: 30,
format: 'MM/DD/YYYY h:mm A',
startDate: moment().subtract('days', 29),
endDate: moment()
});
This is the code I use now.
Taking a look at the documentation on the page you linked, I'd say you need these options:
minDate: (Date object, moment object or string) The earliest date a user may select
maxDate: (Date object, moment object or string) The latest date a user may select
Which probably work something like this:
$('#datrange').daterangepicker({
timePicker: true,
timePickerIncrement: 30,
format: 'MM/DD/YYYY h:mm A',
startDate: moment().subtract('days', 29),
endDate: moment(),
minDate: moment().subtract('days', 100),
maxDate: moment().add('days', 100) // Using moment objects as a example.
});

Categories