TJ Riceball TJ Riceball - 3 years ago 177
C# Question

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

My Model Class looks like this:

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.

Answer Source

In that case you need to store that as a string. You cannot separate Time from Date using BCL (Base Class Library) of .Net. They cannot exist as independent entities.

However youcan have a workaround to save Time in a TimeSpan object using this Representing Time (not date and time) in C#

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download