What is the best way to shorten a datetime that includes milliseconds to only have the second?
For example 2012-01-25 17:24:05.784 to 2012-01-25 17:24:05
2012-01-25 17:24:05.784
2012-01-25 17:24:05
This will truncate the milliseconds.
declare @X datetime set @X = '2012-01-25 17:24:05.784' select convert(datetime, convert(char(19), @X, 126))
or
select dateadd(millisecond, -datepart(millisecond, @X), @X)
CAST and CONVERT DATEADD DATEPART
2.1m questions
2.1m answers
60 comments
57.0k users