Bootstrap Datetimepicker - Set Maxdate Relative To Now?
I use this datetimepicker: http://eonasdan.github.io/bootstrap-datetimepicker/Options/ Basically I want to set maxDate: moment(), i.e maxDate should be limited to now. The problem
Solution 1:
How about using custom version of datepicker plugin?
I have added new parameter maxDateNow
(any ideas for a better name?) that allows selecting date/time up to present time.
$('#datetimepicker1').datetimepicker({maxDateNow: true, format:'DD/MM/YYYY HH:mm'});
See this fiddle
Solution 2:
You can listen to dp.show
event so you can change maxDate
to the current time every time the picker shows. Here a code example:
$('#datetimepicker1').datetimepicker({
maxDate: moment(),
format:'DD/MM/YYYY HH:mm'
}).on('dp.show', function(){
$('#datetimepicker1').data("DateTimePicker").maxDate(moment());
});
<linkhref="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" /><linkhref="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" /><scriptsrc="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script><scriptsrc="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script><scriptsrc="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script><scriptsrc="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script><divclass="form-group"><divclass="input-group date"id="datetimepicker1"><inputtype="text"class="form-control" /><spanclass="input-group-addon"><spanclass="glyphicon-calendar glyphicon"></span></span></div></div>
Solution 3:
I used Liked This, It sets min Date to today's Date
$( '#Field_ID' ).datepicker({dateFormat: 'dd-MM-yy', minDate : newDate()});
Post a Comment for "Bootstrap Datetimepicker - Set Maxdate Relative To Now?"