January 15, 2008 at 5:57 pm
That would be the one... they're pretty smart making it a new datatype... will actually keep 23:59:59.997 code from breaking... unless it's used on the wrong column type.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 16, 2008 at 2:15 pm
Jeff: Good point. I hadn't thought of that.
I just checked two execution plans, using both methods. They were identical, so no performance reason to use either. So that means the >= and < is better. I'll keep that in mind.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
January 16, 2008 at 4:13 pm
Just to flog this topic a little more.
When you are using text stings for dates, you should use the format 'YYYYMMDD HH:MM:SS.MIL'
Example: '20080116 18:01:25.997' (or '20080116' for date only)
This is because it is always interpreted the same by SQL Server and is not affected by the setting of DATEFORMAT or LANGUAGE.
print 'set dateformat mdy'
set dateformat mdy -- Standard US English
select [YYYYMMDD] = convert(datetime,'20080116')
select [YYYY-MM-DD] = convert(datetime,'2008-01-16')
print 'set dateformat ydm'
set dateformat ydm -- Something a little different
select [YYYYMMDD] = convert(datetime,'20080116')
-- Give error
select [YYYY-MM-DD] = convert(datetime,'2008-01-16')
Results:
set dateformat mdy
YYYYMMDD
------------------------------------------------------
2008-01-16 00:00:00.000
(1 row(s) affected)
YYYY-MM-DD
------------------------------------------------------
2008-01-16 00:00:00.000
(1 row(s) affected)
set dateformat ydm
YYYYMMDD
------------------------------------------------------
2008-01-16 00:00:00.000
(1 row(s) affected)
Server: Msg 242, Level 16, State 3, Line 12
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Viewing 3 posts - 16 through 17 (of 17 total)
You must be logged in to reply to this topic. Login to reply