Here is a variation without casting to character and back to datetime, and it only uses two date function calls.Edit: Added code to round down and up, as well as normal rounding.select DT, -- Round down to nearest second DT_Floor_MS = dateadd(ms,-datepart(ms,a.DT),a.DT), -- Round up to nearest second DT_Ceiling_MS = dateadd(ms,(1000-datepart(ms,a.DT))%1000,a.DT), -- Round to nearest second DT_Round_Off_MS = dateadd(ms,500-((datepart(ms,a.DT)+500)%1000),a.DT)from ( -- Test Data select DT = convert(datetime,'14:08:43.000') union all select DT = convert(datetime,'14:08:43.003') union all select DT = convert(datetime,'14:08:43.497') union all select DT = convert(datetime,'14:08:43.500') union all select DT = convert(datetime,'14:08:43.997') union all select DT = convert(datetime,'14:08:44.000') union all select DT = convert(datetime,'23:59:59.997') ) aResults:DT DT_Floor_MS DT_Ceiling_MS DT_Round_Off_MS----------------------- ----------------------- -------- -------------- -----------------------1900-01-01 14:08:43.000 1900-01-01 14:08:43.000 1900-01-01 14:08:43.000 1900-01-01 14:08:43.0001900-01-01 14:08:43.003 1900-01-01 14:08:43.000 1900-01-01 14:08:44.000 1900-01-01 14:08:43.0001900-01-01 14:08:43.497 1900-01-01 14:08:43.000 1900-01-01 14:08:44.000 1900-01-01 14:08:43.0001900-01-01 14:08:43.500 1900-01-01 14:08:43.000 1900-01-01 14:08:44.000 1900-01-01 14:08:44.0001900-01-01 14:08:43.997 1900-01-01 14:08:43.000 1900-01-01 14:08:44.000 1900-01-01 14:08:44.0001900-01-01 14:08:44.000 1900-01-01 14:08:44.000 1900-01-01 14:08:44.000 1900-01-01 14:08:44.0001900-01-01 23:59:59.997 1900-01-01 23:59:59.000 1900-01-02 00:00:00.000 1900-01-02 00:00:00.000(7 row(s) affected)
CODO ERGO SUM