how to set the time range using javascript for the date of input html

Viewed 495

I need to set the date range for my 2 input dates. I know that I can provide min and max values ​​for it but that will force me to select a specific timeframe. What I want to achieve is to choose a date that has been set in the database example: June 2020 - June 2021 so the time span of that data

Does someone know how to dynamically set the max value or what is their range attribute?

1 Answers

Try out minDate and MaxDate attributes... see below Example

Note: I used DateRangePicker

<script type="text/javascript">
var start = new Date('2020-06-1')
var end = new Date('2021-06-1')
  $('#date').datetimepicker({
    format: 'L',
    minDate: start,
    maxDate: end
  });
</script>

Edited:- for Uncertain End Date see Below Example...

<script type="text/javascript">
 var day=0;
 var month=0;
 var year=1; //just pass your date Or Month Or year here,..

 var start = new Date('2020-06-1')
 var end = new Date(start.getFullYear()+year, start.getMonth()+month, start.getDate()+day) 
  $('#date').datetimepicker({
    format: 'L',
    minDate: start,
    maxDate: end
  });
</script>

minDate: (Date or string) The earliest date a user may select.
maxDate: (Date or string) The latest date a user may select.
startDate (Date or string) The beginning date of the initially selected date range. If you provide a string, it must match the date format string set in your locale setting.
endDate: (Date or string) The end date of the initially selected date range.

for More Information See Official Documentation of daterangepicker

Related