Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataType(DataType.Date) format (MVC)

Can we apply somehow the format for this?

[Display(Name = "Date of Birthday")]
[DataType(DataType.Date)]
public DateTime DOB { get; set; }

I'd like to see only Date and not Time.

Thank you!

like image 202
Friend Avatar asked Nov 12 '12 20:11

Friend


1 Answers

You can use the DisplayFormatAttribute

Specifies how data fields are displayed and formatted by ASP.NET Dynamic Data.

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayformatattribute.aspx

[DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]
[Display(Name = "Date of Birthday")]
[DataType(DataType.Date)]
public DateTime DOB { get; set; }
like image 87
Eric J. Avatar answered Sep 29 '22 22:09

Eric J.