﻿<?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 2008 / T-SQL (SS2K8)  / Date Comparison Error / 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>Wed, 22 May 2013 15:33:54 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Date Comparison Error</title><link>http://www.sqlservercentral.com/Forums/Topic1366280-392-1.aspx</link><description>Cannot see any problem with this.  Can you look at supplied code &amp; explain how yours differs.Thanks[code="sql"]--Today I face a problem in Date Comparison please help me in out thanks in advance... --problem mention below:---In my Table there is a Column Named DNCDATE, format of this Column is DateTime. --when i pass a varchar type date then it will not compute any output. --e.g DNCDATE&amp;gt;='29 Sep 2012' when i cast the column then it will give me output -- but it will take longer time to compute the result e.g. CAST( DNCDATE as DATE)&amp;gt;='29 Oct 2012'..--Please guide me about the date comparison and help me out...--Note :- DNCDate Column's Max Value is 2nd Oct 2012, which need to pulled out in our query--=========== TEST DATA ================declare @a as table ( DNCDATE DateTime );insert @a values ( '26 Sep 2012  12:00:00' );insert @a values ( '27 Sep 2012  12:00:00' );insert @a values ( '28 Sep 2012  12:00:00' );insert @a values ( '29 Sep 2012  00:00:00' );insert @a values ( '29 Sep 2012  01:00:00' );insert @a values ( '29 Sep 2012  12:00:00' );insert @a values ( '29 Sep 2012  23:59:59' );insert @a values ( '30 Sep 2012  12:00:00' );insert @a values ( '02 Oct 2012  12:00:00' );--======== QUERY =========select * from @awhere DNCDATE&amp;gt;='29 Sep 2012';--======== RESULTS ============/*DNCDATE-----------------------2012-09-29 00:00:00.0002012-09-29 01:00:00.0002012-09-29 12:00:00.0002012-09-29 23:59:59.0002012-09-30 12:00:00.0002012-10-02 12:00:00.000(6 row(s) affected)*/[/code]Are you using equals:[code="sql"]-- Are you using equals:select * from @awhere DNCDATE='29 Sep 2012';-- This doesn't work because the data type DateTime includes the time.-- This will work though:select * from @awhere DNCDATE &amp;gt;= '29 Sep 2012' AND DNCDATE &amp;lt; '30 Sep 2012';[/code]</description><pubDate>Mon, 01 Oct 2012 03:10:08 GMT</pubDate><dc:creator>laurie-789651</dc:creator></item><item><title>Date Comparison Error</title><link>http://www.sqlservercentral.com/Forums/Topic1366280-392-1.aspx</link><description>Dear All,Greetings!!!!Today I face a problem in Date Comparison please help me in out thanks in advance... problem mention below:-In my Table there is a Column Named DNCDATE, format of this Column is DateTime.  when i pass a varchar type date then it will not compute any output. e.g DNCDATE&amp;gt;='29 Sep 2012' when i cast the column then it will give me output but it will take longer time to compute the result e.g. CAST( DNCDATE as DATE)&amp;gt;='29 Oct 2012'..Please guide me about the date comparison and help me out...Note :-  DNCDate Column's Max Value is 2nd Oct 2012, which need to pulled out in our query</description><pubDate>Sun, 30 Sep 2012 11:33:45 GMT</pubDate><dc:creator>dipanshu.mittal</dc:creator></item></channel></rss>