Home > Back-end >  How to show only date in index view in mvc.net?
How to show only date in index view in mvc.net?

Time:11-17

In Model: public DateTime? FromDate{get;set;} In view:

From Date @Html.EditorFor(model => model.FromDate, new { htmlAttributes = new { @class = "form-control", type = "Date", min = "1944-01-01", max = "2019-01-01" } }) @Html.ValidationMessageFor(model => model.FromDate, "", new { @class = "text-danger" }) [When we enter the date from the DateTime picker calendar it enter the date][1]

In Index view it shows the time also

problem is that I do not want to show the time with the date in the Index view .

CodePudding user response:

To set display format for the DateTime property type use the DisplayFormat attribute in the model declaration, like below:

[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? FromDate { get; set; }    
  • Related