Date field with wrong value

Asked

Viewed 27 times

0

I have the date fields:

 @Html.EditorFor(model => model.DataInicio, new { htmlAttributes = new { @class = "form-control input-sm", @placeholder = "DD/MM/AAAA hh:mm" } })
@Html.EditorFor(model => model.DataFim, new { htmlAttributes = new { @class = "form-control input-sm", @placeholder = "DD/MM/AAAA hh:mm" } })

And the Javascript:

$(function () {
    $('#DataInicio').datetimepicker();
    $('#DataFim').datetimepicker({
        useCurrent: true //Important! See issue #1075
    });
    $("#DataInicio").on("dp.change", function (e) {
        $('#DataFim').data("DateTimePicker").minDate(e.date);
    });
    $("#DataFim").on("dp.change", function (e) {
        $('#DataInicio').data("DateTimePicker").maxDate(e.date);
    });
});

And it was setting normally for the current time but now it starts with the values:

01/01/0001 00:00

Arrows...

Some mistake in the Javascript or in the HTML?

1 answer

1

Usually this happens when the value is null, either from the bank or when the Viewmodel. I usually set my dates as nullable.

public DateTime? DataWhetever { get; set; }
  • It worked partially, is now allowing to set an earlier date to today’s date, which before was not possible...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.