<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"	> <channel><title>Comments on: Round DATETIME to nearest X minute increment</title> <atom:link href="http://www.ideaexcursion.com/2008/08/15/round-datetime-to-nearest-x-minute-increment/feed/" rel="self" type="application/rss+xml" /><link>http://www.ideaexcursion.com/2008/08/15/round-datetime-to-nearest-x-minute-increment/</link> <description>Technology Musings</description> <lastBuildDate>Sat, 04 Feb 2012 00:04:25 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Rob Owen</title><link>http://www.ideaexcursion.com/2008/08/15/round-datetime-to-nearest-x-minute-increment/comment-page-1/#comment-538</link> <dc:creator>Rob Owen</dc:creator> <pubDate>Mon, 23 May 2011 23:39:56 +0000</pubDate> <guid isPermaLink="false">http://www.ideaexcursion.com/?p=4#comment-538</guid> <description>An error is caused by float. Try this on the time 15:12 for example.I changed the convert function toselect		dateadd(day, 0, datediff(day, 0, @time)) + convert(datetime, convert(decimal(12, 7), (round(cast(cast(convert(varchar(12), @time, 14) as datetime) as float) * 1440.0 / @min, 0) / (1440.0 / @min))))</description> <content:encoded><![CDATA[<p>An error is caused by float. Try this on the time 15:12 for example.</p><p>I changed the convert function to</p><p>select		dateadd(day, 0, datediff(day, 0, @time))<br /> + convert(datetime, convert(decimal(12, 7), (round(cast(cast(convert(varchar(12), @time, 14) as datetime) as float) * 1440.0 / @min, 0) / (1440.0 / @min))))</p> ]]></content:encoded> </item> <item><title>By: Gerhard Schmeusser</title><link>http://www.ideaexcursion.com/2008/08/15/round-datetime-to-nearest-x-minute-increment/comment-page-1/#comment-396</link> <dc:creator>Gerhard Schmeusser</dc:creator> <pubDate>Sun, 28 Mar 2010 08:30:25 +0000</pubDate> <guid isPermaLink="false">http://www.ideaexcursion.com/?p=4#comment-396</guid> <description>The mentioned rounding error occured very often when I read data from a linked server. I therefore implemented a different solution:create function dbo.fnrounddatetominutes ( @date smalldatetime        -- rounds to minutes , @minutesBoundary smallint  -- must be between 1 and 60 ) returns smalldatetime as begindeclare @rest int set @rest = datepart(minute, @date) % @minutesBoundaryreturn case when @rest = 0 then @date when @rest &lt; ((@minutesBoundary + 1) / 2) then dateadd(minute, -@rest, @date) else dateadd(minute, @minutesBoundary-@rest, @date) end end go</description> <content:encoded><![CDATA[<p>The mentioned rounding error occured very often when I read data from a linked server. I therefore implemented a different solution:</p><p>create function dbo.fnrounddatetominutes<br /> (<br /> @date smalldatetime        &#8212; rounds to minutes<br /> , @minutesBoundary smallint  &#8212; must be between 1 and 60<br /> )<br /> returns smalldatetime<br /> as<br /> begin</p><p>declare @rest int<br /> set @rest = datepart(minute, @date) % @minutesBoundary</p><p>return<br /> case<br /> when @rest = 0 then @date<br /> when @rest &lt; ((@minutesBoundary + 1) / 2) then dateadd(minute, -@rest, @date)<br /> else dateadd(minute, @minutesBoundary-@rest, @date)<br /> end</p><p>end<br /> go</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Served from: www.ideaexcursion.com @ 2012-02-07 08:47:32 by W3 Total Cache -->
