To date can not be less than From date in ASP.Net MVC

Last Reply 15 days ago By dharmendr

Posted 17 days ago

Hi,

I have two datetimepicker which is fromdate and todate.

I manage to insert both in my database and my issue now is when i need to edit the todate only while fromdate remain the same. and the todate cannot be less that from date

My UI looks like this

https://pasteboard.co/KbQuUx4.png

 

 

 

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <table>
        <tr class="spaceUnder">
            <td style="width: 200px">
                @Html.Label("*", new { style = "color:red" })
                @Html.Label("Pattern")
            </td>
            <td> : </td>
            <td>
                <div class="col-md-5" style="width:40%">
                    @Html.DisplayFor(m => m.PATTERN, Model.PATTERN, new { @class = "form-control", @readonly = "readonly" })
                    @Html.HiddenFor(m => m.PATTERN)
                </div>
            </td>
        </tr>
        <tr class="spaceUnder">
            <td>
                @Html.Label("*", new { style = "color:red" })
                @Html.Label("Valid From")
            </td>
            <td> : </td>
            <td>
                <div class="col-md-5" style="width:40%" id="datetimepicker6">
                    @Html.DisplayFor(m => m.VALIDFROM, @Convert.ToDateTime(Model.VALIDFROM).ToString("dd/MM/yyyy"), new { @class = "form-control", @readonly = "readonly" })
                    @Html.HiddenFor(m => m.VALIDFROM)
                </div>
            </td>
        </tr>
        <tr class="spaceUnder">
            <td>
                @Html.Label("*", new { style = "color:red" })
                @Html.Label("Valid To")
            </td>
            <td> : </td>
            <td>
                <div class="col-md-5 input-group date" style="width:40%" id='datetimepicker7'>
                    @Html.TextBoxFor(a => a.VALIDTO, null, new { @class = "form-control" })
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                    @Html.ValidationMessageFor(a => a.VALIDTO, "", new { @class = "red", @style = "color:red" })
                </div>
            </td>
        </tr>
    </table>
    <div class="col-md-12">
        <input id="Submit" type="submit" name="ActionType" value="Save" class="btn btn-primary" onclick="return confirm('Are you sure want to add data?');" /> @*add onclick function*@
        <input id="Reset" type="reset" name="ActionType" value="Reset" class="btn btn-primary" />
        @Html.BackButton(url)

    </div>
}

 

<script type="text/javascript">
    $(function () {
        var min = $("#datetimepicker6");
        var dateFormat = 'DD-MM-YYYY';

        $("#datetimepicker7").datetimepicker({
            minDate: '0',
            dateFormat: dateFormat,
            onSelect: function (selectedDate) {
                var date = $.datepicker.parseDate(dateFormat, selectedDate)
                var tod = min;
                $from.prop('disabled', false).datepicker("option", "maxDate", new Date(tod));
            }
        });

        var $from = $("#datetimepicker6").datetimepicker({
            dateFormat: dateFormat
        }).prop('disabled', true);
       
    });
</script>

 

The reply you are looking for seems to be deleted or does not exist.