Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 889
Davy8 Avatar asked Apr 05 '09 04:04

Davy8


People also ask

What is the data type for duration in SQL?

The duration type holds relative datetime values. This type provides application developers the ability to store values like “2 minutes” or “3 years.” In other words, values that should not be interpreted as absolute dates or times.

Can SQL date hold time?

sql. Date doesn't hold timezone information, the timezone conversion between our local environment and database server depends on an implementation of JDBC driver. This adds another level of complexity. Finally, let's note, in order to support other SQL data types: SQL TIME and SQL TIMESTAMP, two other java.


1 Answers

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

like image 110
Bob King Avatar answered Oct 12 '22 12:10

Bob King