In Microsoft SQL Server 2000, I have this data.
1900-01-01 00:10:10.830
1900-01-01 00:10:10.430
From the above column, I want to select the datetime and round off the milliseconds, in order to get the below output
1900-01-01 00:10:11
1900-01-01 00:10:10
Thanks in advance
For SQL Server 2008 and above, you can do use DATETIME2
. DATETIME2
is available in SQL Server 2008 and above - for more info see here:
SELECT CAST('1900-01-01 00:10:10.830' AS DATETIME2(0));
SELECT CAST('1900-01-01 00:10:10.430' AS DATETIME2(0));
For earlier version of SQL Sever, for example SQL Server 2000. You can do something like this:
SELECT DATEADD(ms, -DATEPART(ms, DATEADD(ms, 500, CAST('1900-01-01 00:10:10.830' AS DATETIME))) , DATEADD(ms, 500, CAST('1900-01-01 00:10:10.830' AS DATETIME)));
SELECT DATEADD(ms, -DATEPART(ms, DATEADD(ms, 500, CAST('1900-01-01 00:10:10.430' AS DATETIME))) , DATEADD(ms, 500, CAST('1900-01-01 00:10:10.430' AS DATETIME)));