Use SQL Server time datatype in C#.NET application? Use SQL Server time datatype in C#.NET application? sql-server sql-server

Use SQL Server time datatype in C#.NET application?


Here is an MSDN article that reviews all the new Date and Time datatypes introduced in SQL Server 2008 with respect to ADO.NET. As the document says: For System.Data.DbType.Time you would use the .NET Framework type System.TimeSpan


I think you can use TimeSpan datatype for your purpose.Here is an article that explains the use of Time datatype in ADO.NET.


Also even people from Microsoft tend to recommend mapping the sql datatype time to System.Timestamp I would not recommend doing so,

since the range of sql time is 00:00:00.0000000 - 23:59:59.9999999

wheras the range of System.TimeSpan is 10675199.02:48:05.4775808 - 10675199.02:48:05.4775807

which is just slightly different and can lead to nasty runtime out of range errors.