<?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/"
		>
<channel>
	<title>Comments on: Comparing date truncations</title>
	<atom:link href="http://sqlinthewild.co.za/index.php/2008/09/04/comparing-date-truncations/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlinthewild.co.za/index.php/2008/09/04/comparing-date-truncations/</link>
	<description>A discussion on SQL Server</description>
	<lastBuildDate>Tue, 07 Feb 2012 14:50:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: scott2718281828</title>
		<link>http://sqlinthewild.co.za/index.php/2008/09/04/comparing-date-truncations/comment-page-1/#comment-123</link>
		<dc:creator>scott2718281828</dc:creator>
		<pubDate>Thu, 11 Sep 2008 00:50:20 +0000</pubDate>
		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=88#comment-123</guid>
		<description>To time the date operations alone, you should use a SET command that truncates a date variable instead of a SELECT to avoid any influence from I/O or cache.  Put it in a loop that executes a million times, then subtract the time for an empty loop.

I&#039;ve always found the dateadd/datediff method to be fastest. It only requires moving a 32-bit integer.  Casting to a float is a little slower as it requires floating point arithmetic.  Converting to character is terrible as it requires allocating and garbage collecting millions of string objects.</description>
		<content:encoded><![CDATA[<p>To time the date operations alone, you should use a SET command that truncates a date variable instead of a SELECT to avoid any influence from I/O or cache.  Put it in a loop that executes a million times, then subtract the time for an empty loop.</p>
<p>I&#8217;ve always found the dateadd/datediff method to be fastest. It only requires moving a 32-bit integer.  Casting to a float is a little slower as it requires floating point arithmetic.  Converting to character is terrible as it requires allocating and garbage collecting millions of string objects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gail</title>
		<link>http://sqlinthewild.co.za/index.php/2008/09/04/comparing-date-truncations/comment-page-1/#comment-122</link>
		<dc:creator>Gail</dc:creator>
		<pubDate>Tue, 09 Sep 2008 19:28:31 +0000</pubDate>
		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=88#comment-122</guid>
		<description>What kind of numbers did you get?

I can see the dateadd and the cast to float coming out in a different order. They were close in both CPU and execution time.

One thing I did notice (and should have mentioned) is that I forced a MAXDOP 1 on all of the queries when I ran them, as some were running parallel and some were not. I noticed that the parallel plans were significantly slower than the serial plans. Try that, see if it changes things.</description>
		<content:encoded><![CDATA[<p>What kind of numbers did you get?</p>
<p>I can see the dateadd and the cast to float coming out in a different order. They were close in both CPU and execution time.</p>
<p>One thing I did notice (and should have mentioned) is that I forced a MAXDOP 1 on all of the queries when I ran them, as some were running parallel and some were not. I noticed that the parallel plans were significantly slower than the serial plans. Try that, see if it changes things.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DavidB</title>
		<link>http://sqlinthewild.co.za/index.php/2008/09/04/comparing-date-truncations/comment-page-1/#comment-121</link>
		<dc:creator>DavidB</dc:creator>
		<pubDate>Tue, 09 Sep 2008 16:24:21 +0000</pubDate>
		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=88#comment-121</guid>
		<description>Interesting in that my results turned out differently (same table and data as you) as follows;

1. Cast to float to floor
2. Cast to Date
3. DateAdd and Datediff
4. Cast to varchar (sadly this performed as poorly as yours)

So, with that being said, I don&#039;t believe environment should make that much of a difference (dual core laptop with a bunch of memory running 2008). Curious if you have any thoughts why the disparity.</description>
		<content:encoded><![CDATA[<p>Interesting in that my results turned out differently (same table and data as you) as follows;</p>
<p>1. Cast to float to floor<br />
2. Cast to Date<br />
3. DateAdd and Datediff<br />
4. Cast to varchar (sadly this performed as poorly as yours)</p>
<p>So, with that being said, I don&#8217;t believe environment should make that much of a difference (dual core laptop with a bunch of memory running 2008). Curious if you have any thoughts why the disparity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gail</title>
		<link>http://sqlinthewild.co.za/index.php/2008/09/04/comparing-date-truncations/comment-page-1/#comment-120</link>
		<dc:creator>Gail</dc:creator>
		<pubDate>Sun, 07 Sep 2008 11:10:07 +0000</pubDate>
		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=88#comment-120</guid>
		<description>It works in 2008. Won&#039;t work with the datetime2 data type though. But then neither does the method that casts to float.

On the same test box as the others, that one came in at:
CPU time 356ms, execution time 7994 ms</description>
		<content:encoded><![CDATA[<p>It works in 2008. Won&#8217;t work with the datetime2 data type though. But then neither does the method that casts to float.</p>
<p>On the same test box as the others, that one came in at:<br />
CPU time 356ms, execution time 7994 ms</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peso</title>
		<link>http://sqlinthewild.co.za/index.php/2008/09/04/comparing-date-truncations/comment-page-1/#comment-119</link>
		<dc:creator>Peso</dc:creator>
		<pubDate>Sun, 07 Sep 2008 10:00:32 +0000</pubDate>
		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=88#comment-119</guid>
		<description>Same duration, slightly less CPU.
However I think it will not work on SQL Server 2008.

SELECT CAST(CAST(DateValue - 0.50000004 AS INT) AS DATETIME)
FROM #DateTest
GO 4</description>
		<content:encoded><![CDATA[<p>Same duration, slightly less CPU.<br />
However I think it will not work on SQL Server 2008.</p>
<p>SELECT CAST(CAST(DateValue &#8211; 0.50000004 AS INT) AS DATETIME)<br />
FROM #DateTest<br />
GO 4</p>
]]></content:encoded>
	</item>
</channel>
</rss>

