Skip to content Skip to sidebar Skip to footer

Extracting Just Date From Returned Date And Time By Sql Server To Show In Web Pages

I retrieve the date from sql server and want to display the date as 'November 20, 2014' in my view / web page. The problem is SQL server returned the date and time (12/3/2014 12:00

Solution 1:

You just need to format the date. <span>@Model.item.News_Date.ToString("d")</span> should format the date only.

If you can edit your model, you can alternatively add the DisplayFormat attribute:

[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTime News_Date { get; set; }

And if you want to stick with the Html helper method, you can use the Value helper.

@Html.ValueFor(modelItem => modelItem.News_Date, "{0:MM/dd/yyyy}")

Post a Comment for "Extracting Just Date From Returned Date And Time By Sql Server To Show In Web Pages"