Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 399
odiseh Avatar asked Jul 25 '09 09:07

odiseh


People also ask

How do you find the difference between DateTime?

timedelta() method. To find the difference between two dates in Python, one can use the timedelta class which is present in the datetime library. The timedelta class stores the difference between two datetime objects.

How can I get the difference between two Datetimes in C#?

The difference between two dates can be calculated in C# by using the substraction operator - or the DateTime. Subtract() method. The following example demonstrates getting the time interval between two dates using the - operator.

How do I use datediff in Python?

To get the difference between two-time, subtract time1 from time2. A result is a timedelta object. The timedelta represents a duration which is the difference between two-time to the microsecond resolution. To get a time difference in seconds, use the timedelta.


2 Answers

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 P.M., December 31, 9999 A.D. (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

Transact SQL datetime

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

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

like image 94
Marc Gravell Avatar answered Oct 01 '22 12:10

Marc Gravell


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)

like image 34
User Avatar answered Oct 01 '22 12:10

User