When it's being displayed in the the View's datagrid, the dates are shown like 10/20/2016 12:00:00 AM. Can I remove the time using the LINQ in my Controller? I tried converting it to string using different techniques but to no success.
Model
public class UserModel
{
public string userid { get; set; }
public string userdesc { get; set; }
public DateTime startdt { get; set; }
public DateTime enddt { get; set; }
public string status { get; set; }
}
Controller
var users = from u in _odb.USR_MSTR
select new UserModel
{
userid = u.USR_ID,
userdesc = u.USR_DESC,
startdt = u.STRT_DT, //Can I get the date only from this dates?
enddt = u.END_DT,
status = (u.INACTV_DT == null ? "Active" : "Inactive")
};
View
<tbody id="dbBody">
@foreach (var item in Model)
{
<tr>
<td class="hidden">
@Html.DisplayFor(modelItem => item.startdate)
</td>
<td class="hidden">
@Html.DisplayFor(modelItem => item.enddate.ToShortDateString())
</td>
</tr>
}
</tbody>
DateTimewill still have a time portion. This is a display issue, not a retrieval issue.UserModel.startdtis a DateTime and not a string. Do formatting stuff in your view, not in your model.DateTimeand notstringand the OP needs to do the formatting in the view instead of the controller or maybe use attributes as in the duplicate.