What is the best way to represent a timespan in SQL Server CE?

Davy8 picture Davy8 · Apr 5, 2009 · Viewed 13.8k times · Source

Specifically speaking I only need hours:minutes but say I have a .NET TimeSpan object, how should I store that in a SQL(CE) database?

Answer

Bob King picture Bob King · Apr 13, 2009

I'd recommend using a long to represent the number of ticks. That's what TimeSpan uses as it's internal representation. This lets you easily reconstitute your object with the Timespan.FromTicks() method, and output to the database using the Timespan.Ticks property. The smallest unit of time in .NET is the tick, which is equal to 100 nanoseconds