Sunday, September 9, 2007

Datetime rounded to next higher 30th second

/*
-- Datetime time rounded to next higher 30th second.
-- If seconds are between 0 and 29 it will be rounded to 30
-- If seconds are between 30 and 59 it will be rounded to next higher minute
-- can be used for grouping
*/

select distinct crdate, dateadd(ms,-(datepart(ms,crdate) + ((datepart(second,crdate) % 30) * 1000))+ 30000,crdate)as sec30interval
from sysobjects

No comments: