C#中的DateTime和SQL Server中的DateTime之间有什么区别吗?

时间:2022-12-04 08:51:53

Is there any difference between DateTime in c# and DateTime in SQL server?

C#中的DateTime和SQL Server中的DateTime之间有什么区别吗?

3 个解决方案

#1


18  

Precision and range (so, everything important ;-p)

精度和范围(所以,一切都很重要;-p)

From MSDN:

来自MSDN:

.NET System.DateTime

.NET System.DateTime

The DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.)

DateTime值类型表示日期和时间,其值范围从1月1日午夜1点00分,Anno Domini(公共时代)到公元9999年12月31日晚上11:59:59。(C.E。)

Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the GregorianCalendar calenda

时间值以称为刻度的100纳秒单位进行测量,特定日期是自格里高利历日历日历中0001年1月1日午夜12点(格林威治标准时间)以来的刻度数。

Transact SQL datetime

Transact SQL datetime

Date Range: January 1, 1753, through December 31, 9999

日期范围:1753年1月1日至9999年12月31日

Accuracy: Rounded to increments of .000, .003, or .007 seconds

准确度:舍入为.000,.003或.007秒的增量

#2


11  

You can also use datetime2 of SQL Server 2008. The precision there is 100ns as well. In fact, it was introduced to match the .NET DateTime precision.

您还可以使用SQL Server 2008的datetime2。精度也是100ns。实际上,它是为了匹配.NET DateTime精度而引入的。

datetime2 (Transact-SQL)

datetime2(Transact-SQL)

#3


6  

Yes.

是。

The C# equivalent of the SQL datetime type is SqlDateTime

SQL datetime类型的C#等价物是SqlDateTime

So, define the SQL call (stored procs with parameter collection of course) to use SQLDateTime. On advantage is you can trap any overflow or out of range error building the command rather than at execution time from the database engine.

因此,定义SQL调用(当然使用参数集合存储过程)以使用SQLDateTime。优点是您可以捕获构建命令的任何溢出或超出范围的错误,而不是从数据库引擎执行时捕获。

#1


18  

Precision and range (so, everything important ;-p)

精度和范围(所以,一切都很重要;-p)

From MSDN:

来自MSDN:

.NET System.DateTime

.NET System.DateTime

The DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.)

DateTime值类型表示日期和时间,其值范围从1月1日午夜1点00分,Anno Domini(公共时代)到公元9999年12月31日晚上11:59:59。(C.E。)

Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the GregorianCalendar calenda

时间值以称为刻度的100纳秒单位进行测量,特定日期是自格里高利历日历日历中0001年1月1日午夜12点(格林威治标准时间)以来的刻度数。

Transact SQL datetime

Transact SQL datetime

Date Range: January 1, 1753, through December 31, 9999

日期范围:1753年1月1日至9999年12月31日

Accuracy: Rounded to increments of .000, .003, or .007 seconds

准确度:舍入为.000,.003或.007秒的增量

#2


11  

You can also use datetime2 of SQL Server 2008. The precision there is 100ns as well. In fact, it was introduced to match the .NET DateTime precision.

您还可以使用SQL Server 2008的datetime2。精度也是100ns。实际上,它是为了匹配.NET DateTime精度而引入的。

datetime2 (Transact-SQL)

datetime2(Transact-SQL)

#3


6  

Yes.

是。

The C# equivalent of the SQL datetime type is SqlDateTime

SQL datetime类型的C#等价物是SqlDateTime

So, define the SQL call (stored procs with parameter collection of course) to use SQLDateTime. On advantage is you can trap any overflow or out of range error building the command rather than at execution time from the database engine.

因此,定义SQL调用(当然使用参数集合存储过程)以使用SQLDateTime。优点是您可以捕获构建命令的任何溢出或超出范围的错误,而不是从数据库引擎执行时捕获。