Reputation: 44275
I have some DateTime
s in my model. I only want to extract the date in a particular view.
By formatting the data in my view instead of my model, I can give other views the flexibility to use DateTime
or just Date
.
How can I go about formatting my DateTime
in a View?
Upvotes: 0
Views: 106
Reputation: 12369
I usually use -
DateTime date= DateTime.Now;
string onlyDate=date.ToShortDateString();
Upvotes: 1
Reputation: 69953
I may be missing something but it would just be
Model.DateTimeProperty.ToString("mm/dd/yyy")
Or whatever other format you want to use. Same as formatting it anywhere else.
Upvotes: 2
Reputation: 30636
You could do
dateTime.ToShortDateString();
Or
dateTime.ToString("{0:d}");
Or
dateTime.ToString("MM/dd/yyyy");
Upvotes: 5