Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

millisecond in sql tsql

SELECT
    CAST(‘2015-01-01 14:48:34.69’ AS DATETIME) FirstVal,
    CAST(‘2015-01-01 14:48:34:69’ AS DATETIME) SecondVal

When we look at the answer, there is a difference between the milliseconds part in the result set, whereas you can notice that in the SELECT statement I have specified different milliseconds part. The question is why there is a difference in the millisecond part even though I have different value selected?

enter image description here

like image 762
George Avatar asked Nov 18 '15 04:11

George


People also ask

How do I get millisecond in SQL?

We can use DATEPART() function to get the MILLISECOND part of the DateTime in Sql Server, here we need to specify datepart parameter of the DATEPART function as millisecond or mi .

What is Getutcdate () in SQL?

The GETUTCDATE() function returns the current database system UTC date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format.

What is SQL latency?

According to Microsoft SQL Server TechNet, latency is “the delay that occurs while data is processed or delivered.” In networking, latency is typically measured by how much time it takes for a data packet to get from one designated point to another.


1 Answers

DATETIME has an accuracy of 3.33ms - you will never see a value with a .069 stored in a DATETIME - you only ever get .xx0, .xx3 and .xx7.

If you need millisecond precision, use DATETIME2(3) (introduced in SQL Server 2008) as your datatype instead.

like image 178
marc_s Avatar answered Sep 29 '22 10:09

marc_s