1

I have an ASP.NET Core MVC 1.0 app and inside of it a model that contains a DateTime field:

[Display(Name = "Date of Delivery"), DataType(DataType.Date)]
public DateTime? DateOfDelivery { get; set; }

In my Details.cshtml I refer to this field as usual:

@Html.DisplayFor(model => model.DateOfDelivery)

Depending on where I am, the output of this field differs! If I am testing on my local machine, the output is:

20.03.2017

on my on Azure deployed Website, it is:

3/20/2017

These different formats bring me into big trouble, as I am using a datepicker to fill the field in my Create/Edit controllers.

I also tried to set the date format explicit:

[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}", ApplyFormatInEditMode = true), Display(Name = "Date of Delivery"), DataType(DataType.Date)]
public DateTime? DateOfDelivery { get; set; }

This displayed an uniform date (20.03.2017) on both, local machine and Azure. But still the inputs that are accepted differ. Local:

20.03.2017

And on Azure:

03.20.2017

What can I do to ensure, that the accepted dateformat on both, my local machine and also on Azure, are the same? I already read a lot of Stackoverflow questions regarding date topics, but none was able to help me.

Stefan Wegener
  • 726
  • 1
  • 10
  • 25
  • Are you accessing Azure website from the same computer? Is there any language/culture specific cookie put into the response from Azure? From what I know, date input format in HTML5 is unchangeable (take look at http://stackoverflow.com/questions/42275423/date-input-tag-helper-is-not-showing-the-date-from-database/42277305#42277305 ) – Marcin Zablocki Feb 27 '17 at 15:43
  • Sorry for the late response, I was one week off. I am accessing the website from the same computer. I was asking myself if it has anything to do with the region I place the website, but I tried Norther Europe and Western Europe and there was no difference. – Stefan Wegener Mar 06 '17 at 09:10

1 Answers1

1

You can use @Html.TextBoxFor(model => model.DateOfDelivery, "{0:dd.MM.yyyy}") as in this post post

Community
  • 1
  • 1
eldarg
  • 308
  • 2
  • 7