John John
John John

Reputation: 1

How can I display the word "Today" incase the DateTime is within today day

I have the following code inside my razor view in my asp.net MVC web application

<span class="yellow"> @Html.DisplayFor(modelitem=>item.StartDate) </span>

The code displays the DateTime as is in the data base sch as 04/12/2013 05:05:30 AM, which is fine, but how can I do some validation on my view, to display the word "Today" if the DateTime.Date equals today ?

Upvotes: 0

Views: 104

Answers (1)

gdoron
gdoron

Reputation: 150263

@if (item.StartDate.Date != DateTime.Today)
{
    <span class="yellow"> @Html.DisplayFor(modelitem=>item.StartDate) </span>
}
else
{
    <span class="yellow"> Today </span>
}

Upvotes: 6

Related Questions