Solved

SQL2000 - Two different DateTime values return equal

Posted on 2006-07-11
4
651 Views
Last Modified: 2008-01-09
Can anyone tell me why it is that Sql Server 2000 returns 1 on the this?:

Declare @firstDate DateTime
Select @firstdate = '6/15/2006'
Select 1 where '6/14/2006 23:59:59.999' = @firstDate

These are two separate DateTime values, but yet SQL Server 2000 seems to think they are equal... This threw a reporting query of mine off simply because the statement returns true in my match criteria.
0
Comment
Question by:realevergod
  • 3
4 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 125 total points
ID: 17085719
Hi realevergod,

The datetime data type does not have the ability to resolve differences larger than 0.03 seconds, so
6/14/2006 23:59:59.999 rounds up to 6/15/2006 0:00:00

Regards,

Patrick
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 17085726
> resolve differences larger than 0.03 seconds

Sorry, meant SMALLER than :)

Regards,

Patrick
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17085733
I could reproduce your problem, I went even a step further (no solution):

Declare @firstDate DateTime
Select @firstdate = convert(datetime,'6/15/2006',101)
declare @lastdate datetime
select @lastdate = convert(datetime, '2006-06-14 23:59:59.999', 121)
Select 1 where @lastdate = @firstDate
select convert(varchar(30), @firstdate, 121), convert(varchar(30), @lastdate, 121)

Listening & Learning
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 17085739
realevergod,

Sorry, the smallest resolution is not 0.03 seconds, but rather 1/300th of a second, or about 0.00333 seconds.
But SQL Server still has to round yours up.

Regards,

Patrick
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now