Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save time only without the date using ASP.NET MVC 5 Data Annotation "DataType.Time?

My Model Class looks like this:

 [DataType(DataType.Time)]
 public DateTime Time {get; set;}

When I run it, I have a cool an HTML 5 Input Type in Time. When I save the data, the value in my database looks like this:

 7/11/2014 1:00AM

It automatically saves the current date. I just wanna have the time saved. I'm trying to create a reservation system.

like image 819
TJ Riceball Avatar asked Jul 11 '14 08:07

TJ Riceball


1 Answers

[DataType(DataType.Time)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:HH:mm}")]
public DateTime Hour { get; set; }
like image 75
Jorge L Hernandez Avatar answered Nov 14 '22 22:11

Jorge L Hernandez