Skip to content

Instantly share code, notes, and snippets.

View radleta's full-sized avatar

Richard Adleta radleta

View GitHub Profile
@radleta
radleta / Nearest5Minutes.sql
Created March 22, 2019 14:29
Round DateTime to nearest 5 minutes. Useful when grouping by DateTime to round to the nearest 5 minutes.
SELECT dateadd(minute, datediff(minute, '1900-01-01', dateadd(second, 150, GETDATE()))/5*5, 0)
@radleta
radleta / NearestHour.sql
Created December 24, 2013 13:25
Round DateTime to nearest hour. Useful when grouping by DateTime to round to the nearest hour.
SELECT dateadd(hour, datediff(hour, 0, GETDATE()), 0) NearestHour
@radleta
radleta / NearestMinute.sql
Created December 24, 2013 13:23
Round DateTime to Nearest Minute. Useful when grouping by DateTime to round to the nearest minute.
SELECT DATEADD(MINUTE, 1+DATEDIFF(MINUTE, 0, GETDATE()), 0) NearestMinute