简体   繁体   中英

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

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

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

From MSDN:

.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 PM, December 31, 9999 AD (CE)

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 AD (CE) in the GregorianCalendar calenda

Transact SQL datetime

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

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

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.

datetime2 (Transact-SQL)

Yes.

The C# equivalent of the SQL datetime type is 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM