What are equivalent C# data types for SQL Server's date, time and datetimeoffset?

Viewed 48938

What are the most suitable equivalent C# data types for the date datatypes in SQL Server? I'm specifically looking for

  • date
  • time
  • datetimeoffset
3 Answers

Here are the equivalent CLR data types for date, time and datetimeoffset SQL Server data types:

date - DateTime, Nullable<DateTime>
time - TimeSpan, Nullable<TimeSpan>
datetimeoffset - DateTimeOffset, Nullable<DateTimeOffset>

Note that you can find a listing of all SQL Server data types and their CLR equivalents here, Mapping CLR Parameter Data

The new types are supported only if you install .NET Framework 3.5 SP1.

  • SqlDbType.Date

  • SqlDbType.Time

  • SqlDbType.DateTime2

  • SqlDbType.DateTimeOffSet

For exhaustive information, see Date and Time Data in SQL Server 2008

Related