SQL Server 的日期、时间和日期时间偏移量的等效 C# 数据类型是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/655049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 12:03:22  来源:igfitidea点击:

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

c#sql-server-2008types

提问by Paul Suart

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

SQL Server 中日期数据类型的最合适的等效 C# 数据类型是什么?我专门找

  • date
  • time
  • datetimeoffset
  • date
  • time
  • datetimeoffset

采纳答案by Jay Riggs

Here are the equivalent CLR data types for date, timeand datetimeoffsetSQL Server data types:

下面是等效的CLR数据类型datetime以及datetimeoffsetSQL Server数据类型:

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

日期- DateTimeNullable<DateTime>
时间- TimeSpanNullable<TimeSpan>
日期时间偏移- DateTimeOffsetNullable<DateTimeOffset>

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

请注意,您可以在此处找到所有 SQL Server 数据类型及其 CLR 等效项的列表,映射 CLR 参数数据

回答by Cerebrus

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

仅当您安装 .NET Framework 3.5 SP1 时才支持新类型。

  • SqlDbType.Date

  • SqlDbType.Time

  • SqlDbType.DateTime2

  • SqlDbType.DateTimeOffSet

  • SqlDbType.Date

  • SqlDbType.Time

  • SqlDbType.DateTime2

  • SqlDbType.DateTimeOffSet

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

有关详尽信息,请参阅SQL Server 2008 中的日期和时间数据

回答by splattne

In C# you could use

在 C# 中,你可以使用