In this team ASP.NET MVC project, there's a JPStudent
index view with the lambda expression:
@Html.DisplayFor(modelItem => item.JPStartDate)
JPStartDate
is a DateTime
property of the JPStudent
model. The Index
view returns a time stamp with the date, but I need it to display only day, month and year.
I know the common answer is to convert the DateTime
to string in order to do this. At first, I was going to convert it to string and add it as another property to the list, since I need to maintain the same lambda expression which returns item.JPStartDate
(I'm not supposed to mess with that expression, as per team rules). I would've then switched out the item.JPStartDate
in the expression for the new property. However, I get errors in my model file when I try to add the date string as a new property in the properties list.
The JPStudentsController
sets:
jPStudent.JPStartDate = DateTime.Now;
So I tried my string conversion to ddmmyy
here, and got
Cannot implicitly convert string to DateTime
errors. I'm a little stumped here. I need to extract only the day, month and year but without messing with the way the Index
view is set up to return the date property to the view.
Does anyone have any suggestions in this particular situation? I may be missing some simple way of doing it that I'm just not thinking of right now. If anyone has any suggestions for isolating day, month and year from DateTime
, I'd really appreciate it!