0

I'm using .net razor to display the date of football matches, I'm trying to only display the matches that are going to happen within the next week. The problem is that my date is currently a String, it looks like: "Saturday 23rd January 2016".

@foreach (var dateItem in Model.Select(i => i.date).Distinct().ToList())
{
DateTime dt = DateTime.ParseExact(dateItem, "D", null);
<tr>

@if ((DateTime.Now - dt).TotalDays < 5)
{
<tr>
    <th>
        @Html.DisplayFor(modelItem => dateItem)
    </th>
</tr>
<tr>
    <th>

This is what I've tried so far with no luck

brian muir
  • 17
  • 1
  • 2
    Check MSDN's "Date and Time formatting strings" page and try again. – CodeCaster Jan 26 '16 at 11:27
  • Please see http://stackoverflow.com/questions/28114874/html-displayfor-dateformat-mm-dd-yyyy and http://stackoverflow.com/questions/6001654/how-to-render-a-datetime-in-a-specific-format-in-asp-net-mvc-3 – Roman Marusyk Jan 26 '16 at 11:36
  • you should display dt.toString() not dateItem – lyz Jan 26 '16 at 11:38

0 Answers0