﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server Express  / Remove Time from DateTime / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 20 Jun 2013 03:10:53 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Remove Time from DateTime</title><link>http://www.sqlservercentral.com/Forums/Topic1417914-324-1.aspx</link><description>What I was trying to achieve was to work out why the insert created the exception below every now and again and the initial analysis pointed to the DATEADD format but ended up being more complicated.System.Data.SqlClient.SqlException (0x80131904): Violation of UNIQUE KEY constraint. Cannot insert duplicate key in object.The end result was as follows:1) Both of the DATEADD method formats produce the exact same result, so you can use either, but the 0 as date argument "feels" better.2) The WHERE NOT EXIST does not guarantee (no atomic action) that the condition DOES NOT EXIST as the thread can be interrupted in between the select and the insert, which creates the exception.3) Always double and triple check the calling code to make sure that it's not calling the SQL without wrapping the code in an exception and trying again WHEN it fails if needs be. In this case, I just needed to ignore the exception.One thing I must say, it was a very interesting learning exercise.</description><pubDate>Thu, 07 Mar 2013 17:05:27 GMT</pubDate><dc:creator>Scott Anderson #2</dc:creator></item><item><title>RE: Remove Time from DateTime</title><link>http://www.sqlservercentral.com/Forums/Topic1417914-324-1.aspx</link><description>In the DateAdd function, third parameter is date. 2nd parameter is the increment.When you write DATEADD(d,0,getdate()) 0 days are added to current date.When you write DATEADD(d, DATEDIFF(d, 0, @Today), 0);the date here is 0, select cast(0 as datetime) -- 1900-01-01 00:00:00.000I'm not sure what you are trying to achieve here.</description><pubDate>Thu, 07 Mar 2013 03:28:56 GMT</pubDate><dc:creator>Arjun Sivadasan</dc:creator></item><item><title>Remove Time from DateTime</title><link>http://www.sqlservercentral.com/Forums/Topic1417914-324-1.aspx</link><description>What is the difference between these 2 lines in SQL Server 2005 Express?[code="sql"]DATEADD(d, 0, DATEDIFF(d, 0, @Today));[/code]and[code="sql"]DATEADD(d, DATEDIFF(d, 0, @Today), 0);[/code]Other than making this statement fail at random times:[code="sql"]DECLARE @DateSrc DATETIME;-- Chop off the time part:SET @DateSrc = DATEADD(d, 0, DATEDIFF(d, 0, @Today));INSERT INTO dbo.SeqNo(MyGUID, TheDay, LastNo)SELECT @MyGUID, @DateSrc, 0WHERE NOT EXISTS (   SELECT 1 FROM dbo.SeqNo AS sn  WHERE sn.MyGUID = @MyGUID AND sn.TheDay = @DateSrc   );[/code]</description><pubDate>Fri, 08 Feb 2013 14:49:48 GMT</pubDate><dc:creator>Scott Anderson #2</dc:creator></item></channel></rss>