0

I have a ViewModel that displays my table

Model

public DateTime? startdate { get; set; }

Controller

var regions = from r in _odb.REGION_MSTR
              select new RegionModel
              {
                  regionid = r.REG_ID,
                  regionname = r.REG_NAME,
                  status = (r.INACTV_DT == null ? "Active" : "Inactive"),
                  startdate = r.STRT_DT
              };

View

<tbody id="dbBody">
    @foreach (var item in Model)
    {
        <tr>
            ...
            <td class="hidden">
                @Html.DisplayFor(modelItem => item.startdate)
            </td>
        </tr>
    }
</tbody>

This will display a 9/16/2016 12:00:00 AM. How do I remove the 12:00:00 AM? I tried using DbFunctions.TruncateTime(r.STRT_DT), but still getting date with time.

2 Answers2

0

You can try this

@Html.DisplayFor(m => m.startdate, "{0:dd/MM/yyyy}")

Source: Display DateTime value in dd/mm/yyyy format in Asp.NET MVC

Community
  • 1
  • 1
REDEVI_
  • 684
  • 8
  • 18
0

try this in your controller

    startDate = r.strt_DT.Date

Format to use

 StartDate = r.strt_DT.Date

try using like this

EntityFunctions.TruncateTime(x.StartDate ) == r.strt_DT.Date
Liam
  • 27,717
  • 28
  • 128
  • 190
Aman Goel
  • 21
  • 1
  • 4