SQL Server – Difference Between DATETIME and DATETIME2

I came across the article written by Pinal Dave about the difference between DATETIME and DATETIME2. In my years working as a database administrator, I did use DATETIME most of the time for database structure design. So far, I did not use the data type DATETIME2 before.

It becomes more interesting when he shared with us the problems when using DATETIME2 and SYSDATETIME(). In a short summary he commented as below:-

The best way is to use GETDATE() if you are using DATETIME, and SYSDATETIME() if you are using DATETIME2 to populate them with current date and time for accurately addressing the precision. As DATETIME2 is introduced in SQL Server 2008, the above script will only work with SQL Server 2008 and later versions.

Read Pinal Dave full article, https://blog.sqlauthority.com/2010/06/11/sql-server-difference-between-datetime-and-datetime2/

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s