Round datetime to nearest 5 minutes

This took me forever to find online, so I’m posting it here for the next helpless soul. If you need to round datetimes coming out of sql to the nearest 5 minutes, here you go.

dateadd(mi,(datepart(mi,dateadd(mi,1,DateTimeColumn))/5)*5,dateadd(hh,datediff(hh,0,dateadd(mi,1, DateTimeColumn)),0))

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>