MVC Datepicker format

1.1k Views Asked by At

I'm creating a website in ASP.NET and am currently trying to show a datepicker on the webpage. I can get the datepicker to show the calendar and accept input, but it's never in the right format. When first displayed it is shown as "dd/mm/yyyy" which is what I want, but as soon as I select it it changes to "mm/dd/yyyy".

For example, the data loaded in has the date "10/08/2017" as in the 10th Aug 2017. When I click the datepicker to change the date it shows the calendar with the month as October and the selected date as the 8th (the wrong way round).

Is this a programming problem? Or is this to do with how my Chrome is configured?

This is the property bound to:

[Column(TypeName = "date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
[DisplayName("Expiry")]
public DateTime? MembershipExpires { get; set; }

This is the html:

@Html.EditorFor(model => model.MembershipExpires, new { htmlAttributes = new { @class = "form-control datepicker", id = "end_date", name = "end_date" } })

This is the JS:

$('#end_date').datepicker(
{
    changeMonth: true,
    changeYear: true,
    yearRange: "1950:c+50",
    minDate: null,
    dateFormat: 'dd/mm/yyyy'
});

Thanks guys

0

There are 0 best solutions below