Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Granularity of SQL datetime

Tags:

sql

ado.net

t-sql

I have a datetime column in the db and when I test setting it


DateTime dateTime = DateTime.Now;
state.LastUpdated = dateTime;
Assert.AreEqual(dateTime , state.LastUpdated);

I get the following error
Assert.AreEqual failed. Expected:<3/2/2011 9:52:32 AM>. Actual:<3/2/2011 9:52:00 AM>.

What's the granularity of SQL datetime and is it possible to tune it for more granularity?

like image 392
kateroh Avatar asked Mar 13 '26 14:03

kateroh


1 Answers

Use datetime2, which has up to 100 nanoseconds precision. msdn.microsoft.com/en-us/library/bb677335.aspx

Noted by @Remus in a comment, posting it as an answer for posterity.

like image 87
Remi Despres-Smyth Avatar answered Mar 16 '26 06:03

Remi Despres-Smyth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!