tags:

views:

89

answers:

5

I have a Time column in a DataBase table. The date is not important, we just want a time in the day. What type would be best to represent it in C#? I was going to use a DateTime, but I don't like the idea of having a date.

Any idea?

Thanks!

+4  A: 

You could use a TimeSpan structure to represent a time in .NET.

dommer
But isn't a TimeSpan a range of time? Apparently, the end time is unknown, the event could just start at 2pm and last indefinitely. Would it still be a good idea to use a TimeSpan?
Carlo
But a time of day is really just the time elapsed since midnight. So, the same concept, really.
dommer
I'll give this one a shot. Thank you.
Carlo
+2  A: 

Jon Skeet's been working on something called Noda Time, maybe this will help:

http://code.google.com/p/noda-time/wiki/Welcome?tm=6

code4life
A: 

Use a Timespan to represent the time span from midnight to the time.

Guffa
A: 

You could try something like this

TimeSpan ts = DateTime.Now.TimeOfDay

Where you are applying the time property of the DateTime object and just use that.

Dan Snell
A: 

I would use a TimeSpan to represent this, with the TimeSpan being the span of time since midnight. This correlates to DateTime's TimeOfDay property in the framework.

Reed Copsey