I'm trying to convert a string to datetime like this select CONVERT(datetime, '31-05-2022 04:00:00.105', 105)
but the precision of the milliseconds changes. How is it possible ?
In my case it gives me 2022-05-31 04:00:00.107
Thanks for your help.
CodePudding user response:
Datetime is only accurate to 3.33 milliseconds. If you try to wedge a value in that is more precise than that, MS SQL will round to the near acceptable value. More information is available here:
Milliseconds in my DateTime changes when stored in SQL Server
CodePudding user response:
You could try the 'datetime2' (or 'datetimeoffset') column type to account for the greater precision required
select CONVERT(datetime2, '31-05-2022 04:00:00.105', 105)