How to fix the MVC Textbox date time format issue

Posted written by Paul Seal on March 23, 2018 .NET Framework

Today I had a problem where I had a text box which was rendering a date of birth, but it was also showing the time as well.

This post shows you how you can remove the time off the end of a date value when rendering it in an MVC TextBoxFor.

This is the markup I was using before:

@Html.TextBoxFor(m => m.DateOfBirth)

Here is the solution:

@Html.TextBoxFor(m => m.DateOfBirth, "{0:d}")

Hopefully this post will help you and probably me when I forget it in a few weeks.