Monday, June 3, 2024
151
rated 0 times [  156] [ 5]  / answers: 1 / hits: 17885  / 8 Years ago, thu, august 18, 2016, 12:00:00

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 is by the time the datepicker is opened maxDate is not now() anymore.
I want to set it maxDate to now everytime the datepicker is shown.



I want to enforce it globally if possible, not to specify it on every datetimepicker() instance. Is it possible to somehow give a relative date to now using moment.js ?



See this fiddle:

https://jsfiddle.net/0Ltv25o8/3281/

I set maxDate to now. You'll see after minute from the page load, you won't be able to choose the current minutes using the arrow buttons.


More From » twitter-bootstrap

 Answers
28

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


[#60995] Tuesday, August 16, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
heidys

Total Points: 665
Total Questions: 102
Total Answers: 97

Location: Belarus
Member since Sat, Jul 18, 2020
4 Years ago
;