Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

  • date
  • time
  • datetimeoffset
like image 437
Paul Suart Avatar asked Mar 17 '09 16:03

Paul Suart


People also ask

What is the equivalent of class in C?

There is nothing equivalent to classes . Its a totally different paradigm. You can use structures in C. Have to code accordingly to make structures do the job.


2 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

like image 192
Jay Riggs Avatar answered Sep 22 '22 13:09

Jay Riggs


In C# you could use

  • Date
  • TimeSpan
  • DateTimeOffset Structure
like image 40
splattne Avatar answered Sep 23 '22 13:09

splattne