Martin Fox
Martin Fox

Reputation: 33

Using convert in SQL Server returns a wrong number of milliseconds

Why in SQL Server if I do this:

SELECT CONVERT(datetime, '2020-06-23 23:21:22.302', 121)

I get this date:

2020-06-23 23:21:22.303

Upvotes: 0

Views: 46

Answers (2)

Rodney Ellis
Rodney Ellis

Reputation: 807

Try this:

SELECT convert(datetime, '2020-06-23 23:21:22.302', 121)
SELECT convert(datetime2, '2020-06-23 23:21:22.302', 121)
SELECT convert(datetime2(3), '2020-06-23 23:21:22.302', 121)

Upvotes: 2

cpalmer
cpalmer

Reputation: 311

see this thread

Its because datetime in SQL Server is only accurate to 3ms and will round to increments of of .000, .003, or .007 seconds

Upvotes: 5

Related Questions