JSFiddle - React, Tailwind, and code Playground
by Amol Tate
HTML
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<input type="text" id="from_date" placeholder="From Date" />
<input type="text" id="to_date" placeholder="To Date" />
JavaScript
$(document).ready(function(){
$('#from_date').datepicker( {
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd",
maxDate: new Date(),
onSelect: function (selectedDate) {
var orginalDate = new Date(selectedDate);
var monthsAddedDate = new Date(new Date(orginalDate).setMonth(orginalDate.getMonth()));
//$("#to_date").datepicker("option", 'minDate', selectedDate);
$("#to_date").datepicker("option", 'maxDate', monthsAddedDate);
}
}).click(function(){
$('.ui-datepicker-calendar').show();
});
$('#to_date').datepicker( {
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd",
maxDate: new Date(),
onSelect: function (selectedDate) {
var orginalDate = new Date(selectedDate);
var monthsAddedDate = new Date(new Date(orginalDate).setMonth(orginalDate.getMonth() - 1));
$("#from_date").datepicker("option", 'minDate', monthsAddedDate);
$("#from_date").datepicker("option", 'maxDate', selectedDate);
}
}).click(function(){
$('.ui-datepicker-calendar').show();
});
});