November 30, 2007 at 9:04 am
So I was playing with the ISDATE function and scripted this:
DECLARE@Datum2 datetime
SET @Datum2 = ''
SELECT ISDATE(@Datum2)
SELECT @Datum2
To my amazement a date is returned: 1900-01-01 00:00:00.000
And thus the ISDATE returns a valid date, which means problems for me, but that's an aside. Is there a reason I should be aware of for this behaviour?
Greetz,
Hans Brouwer
November 30, 2007 at 9:44 am
a little odd, but since you declared your variable a datetime, and initialized it by setting it to '' it looks like sql server set it to 0, or the first date a datetime can be.
the isdate function will always return true on a variable declared as a datetime (Unless its null).
the isdate function is more usefull on a parameter, or string that is not declared a datetime
declare @myVar varchar(100)
-- @Myvar is NULL
select isdate(@Myvar)
-- Initialized
set @myVar = ''
select isdate(@Myvar)
--Result
--0
-- Set to a real date
set @myvar='11/30/2007'
select isdate(@Myvar)
--Result
--1
set @myvar='Not a Date'
select isdate(@Myvar)
--Result
--0
November 30, 2007 at 11:59 am
Not odd behaviour... same as what happens with most numeric datatypes...
DECLARE @Datum2 INT
SET @Datum2 = ''
SELECT @Datum2
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply