George
George

Reputation: 61

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

Upvotes: 6

Views: 478

Answers (3)

Srikanth Lanka
Srikanth Lanka

Reputation: 67

Click here to see the diff

It's because you have selected different time is milliseconds.

Upvotes: 0

marc_s
marc_s

Reputation: 754963

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.

Upvotes: 5

devnath
devnath

Reputation: 36

you have selected Diff Value in First Value:-34.69 and Second Value :- 34:69. you can see both value diff so out put diff.

Upvotes: 0

Related Questions