Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between DateTime and DateTime2 [duplicate]

Tags:

.net

dbtype

Possible Duplicate:
SQL Server datetime2 vs datetime

What is the difference between DbType.DateTime and DbType.DateTime2 in .NET?

If I am using DbType.Date and I want to change to a DateTime type should I use DateTime or DateTime2?

like image 781
CJ7 Avatar asked Aug 17 '10 02:08

CJ7


People also ask

What is the difference between DATETIME2 and datetime?

Datetime2 has fractional seconds precision of 7 which means that there are 7 digits representing the nanosecond value whereas DateTime has a precision of 3.

What is a DATETIME2 data type?

The DATETIME2 data type specifies a date and time with fractional seconds. DATETIME2 supports dates from 0001-01-01 through 9999-12-31. The default value is 1900-01-01 00:00:00. The time is based on a 24-hour clock.

What is the difference between datetime and timestamp data types in SQL Server?

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.


2 Answers

DbType.DateTime and DbType.DateTime2 both map to the .NET type System.DateTime. If you need to have additional precision and dates that go back before 1753, then use DateTime2; otherwise DateTime will suffice.

This MSDN link explains it pretty well.

Hope this helps!

like image 58
David Hoerster Avatar answered Sep 20 '22 09:09

David Hoerster


DbType.DateTime2 and DbType.DateTime mirror exactly the types found in SQL Server as stated by this post.

When I do SQL Server work, I don't usually need that extra resolution, nor do I go back to 1753, so in .NET I tend to use System.DateTime for this and not either one. If you need to go way back in time or need mad precision, use DbType.DateTime2 paired with a SQL Server type of DateTime2.

So in short, if you're programming using Access, you probably shouldn't be using either one.

like image 30
Dave Markle Avatar answered Sep 22 '22 09:09

Dave Markle