Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add exactly 1 millisecond?

select getdate(),DATEADD(millisecond,1,getdate())

yields me same answer....How to add exactly 1 millisecond?

I cannot use a datetime2 field.

like image 907
priyanka.sarkar Avatar asked Mar 21 '12 12:03

priyanka.sarkar


3 Answers

You can't. The accuracy of datetime is 3.33 milliseconds.

Date and Time

like image 31
Mikael Eriksson Avatar answered Nov 15 '22 11:11

Mikael Eriksson


The resolution of the DATETIME type is insufficient for your needs; per the documentation, it is:

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

like image 28
Rowland Shaw Avatar answered Nov 15 '22 10:11

Rowland Shaw


You'll need to store milliseconds separately if you need that much accuracy. In SQL Server 2005 there is no native date/time type that will allow you to be more precise than ~3 ms. This is why, for example, the last time you can have in a day is 23:59:59.997, not .998 or .999.

like image 145
Aaron Bertrand Avatar answered Nov 15 '22 12:11

Aaron Bertrand