Quantcast
Channel: SQL Server
Viewing all articles
Browse latest Browse all 3819

Blog Post: Round a datetime to the nearest minute (or down to the minute)

$
0
0
Last week I was doing a comparison of 2 datetime fields, but I only wanted to do the comparison on the minute level. So I needed something to round the datetime to the nearest minute or down to the minute. I found this great answer on SO : DECLARE @dt DATETIME SET @dt = '09-22-2007 15:07:38.850' SELECT DATEADD(mi, DATEDIFF(mi, 0, @dt), 0) And if you want to round up or down, you can add 30 seconds to the parameter like this: SELECT DATEADD(mi, DATEDIFF(mi, 0, DATEADD(s, 30, @dt)), 0)

Viewing all articles
Browse latest Browse all 3819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>