Returning only date part of datetime string in editorfor template

155 views Asked by At

I have the following code to try and return my datetime value from my Editorfor template in the dd/MM/yyyy format without the time value:

@Html.EditorFor(c => c.SelectedContent.ExpiryDate, "{0:dd/MM/yyyy }")

This however is returning also the time value but it is not what I need, how can I return this so it is only the date?

1

There are 1 answers

5
Paddyd On BEST ANSWER

Place the following line above where you declare ExpiryDate in your model

[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]