Monthly Archives: August 2016

Linked fields with datetimepicker

While using the Bootstrap DateTime Picker, it is often handy to link two fields for a date range. For example, a stop date (to) should not be before a start date (from). Here’s how…


var now = new Date();

$("#from_").datetimepicker({
format: "mm/dd/yyyy",
linkField: "from",
linkFormat: "yyyy-mm-dd",
minView: 2,
endDate: now
}).on('changeDate', function(ev){
$('#to_').datetimepicker('setStartDate', ev.date);
});

$("#to_").datetimepicker({
format: "mm/dd/yyyy",
linkField: "to",
linkFormat: "yyyy-mm-dd",
minView: 2,
endDate: now
}).on('changeDate', function(ev){
$('#from_').datetimepicker('setEndDate', ev.date);
});

This also has linked fields for submitting a date in a preferred format and today’s date for an upper limit (useful for reports).