Date Range Validation

<div id="div1">
    <input type="date" name="date1" id="date1" min="2020-01-01" max="2020-12-31"/>
    <input type="date" name="date2" id="date2" onchange="compare(this)" />
</div>
@section scripts{ 
<script>
    function compare(item) {
        if (new Date($(item).val()) > new Date("2020-7-14")) {
            $(item).attr("value", "");
            $("#date2").remove();
            var date2 = '<input type="date" name="date2" id="date2"  onchange="compare(this)" />';
            $("#div1").append(date2);
        }

    }
</script>