NetBrain Solutions

NetBrain Solutions

  • 1.4k
  • 315
  • 2.4k

DateTime format in ASP.NET Core

Jan 14 2022 9:25 AM

I am using ASP.NET Core (.net framework 5.0, Visual studio 2019) &  want to set date format as yyyy-mm-dd. 

here are my current code

In Model =>

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-mm-dd}", ApplyFormatInEditMode = true)]

public DateTime? DOB { get; set; }

(also tried with ApplyFormatInEditMode = false)

In view =>

@Html.EditorFor(x => x.DOB)

tried both ways but still getting the mm/dd/yyyy format.

What is wrong with the codes & what I can do ?


Answers (1)