Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ISDATE


ISDATE

Author
Message
Lokesh Vij
Lokesh Vij
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1716 Visits: 1599
Comments posted to this topic are about the item ISDATE

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter


Raghavendra Mudugal
Raghavendra Mudugal
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1758 Visits: 2958
Thank you Lokesh-ji, Nice question.

(So simple and yet it keeps us thinking..., to be honest I selected E,E and then seeing 2nd one's datatype as varchar, but the ISDATE takes nvarchar, so i thought again E,1 and possibly by thinking that it might return 1. Luck is playing a fair role with me in answering the question, but not a good practice for me like this, I need to be more consistent in my choice. :-) )

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
kaspencer
kaspencer
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2410 Visits: 820
As a matter of fact, SQL Server 2005 copes with this very well, provided that the data type is changed to DATETIME.

It would seem that in SQL Server 2005 at least, DATETIME is perfectly acceptable as a datatype for ISDATE(), although as the datatype DATE does not exist in that version, it cannot be considered.

All this makes me think that the SQL Server core developers might just have forgotten about the new data type so far as ISDATE() is concerned!

Thus, on changing DATE to DATETIME, SQL Server 2005 return 1, 1. That's why I falied this question, having assumed that SQL 2008 onwards would be fine with DATE.

Ken.

You never know: reading my book: "All about your computer" might just tell you something you never knew!
lulu.com/kaspencer
Lokesh Vij
Lokesh Vij
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1716 Visits: 1599
kaspencer (8/28/2012)
As a matter of fact, SQL Server 2005 copes with this very well, provided that the data type is changed to DATETIME.

It would seem that in SQL Server 2005 at least, DATETIME is perfectly acceptable as a datatype for ISDATE(), although as the datatype DATE does not exist in that version, it cannot be considered.

All this makes me think that the SQL Server core developers might just have forgotten about the new data type so far as ISDATE() is concerned!

Thus, on changing DATE to DATETIME, SQL Server 2005 return 1, 1. That's why I falied this question, having assumed that SQL 2008 onwards would be fine with DATE.

Ken.


Agreed! For this reason the question states that this scenario is applicable for SS 2008 and above :-)

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter


Lokesh Vij
Lokesh Vij
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1716 Visits: 1599
Raghavendra Mudugal (8/27/2012)
Thank you Lokesh-ji, Nice question.

(So simple and yet it keeps us thinking..., to be honest I selected E,E and then seeing 2nd one's datatype as varchar, but the ISDATE takes nvarchar, so i thought again E,1 and possibly by thinking that it might return 1. Luck is playing a fair role with me in answering the question, but not a good practice for me like this, I need to be more consistent in my choice. :-) )





Glad to know that you liked the question :-)

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter


Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8748 Visits: 11718
An interesting question - especially because the correct answer (and it is correct, as can be easily proven by running the code) is not what the documentation predicts.

The documentation on ISDATE (linked in the answer explanation) says: "expression -- Is a character string or expression that can be converted to a character string."
The documentation on converting (http://msdn.microsoft.com/en-us/library/ms187928.aspx) says that implicit conversions from date to character strings (char, varchar. nchar, and nvarchar) are allowed. As can also be easily verified by running the code below.

So according to the documentation, the ISDATE should convert the date to character string, then test if it's a valid date. Just as it does, and always has done, when fed a datetime argument.

The text of the error message indicates that this is a deliberate change of behaviour between the date data type and the old datetime data type, so my guess is that this is a documentation bug.


EDIT: Forgot to paste in the demo code...

-- Show that date will implicitly convert to string
DECLARE @dt1 DATE = '20120828';
SELECT RTRIM(@dt1);
go

-- Show that datetime will work in ISDATE (even on SQL 2008 and SQL 2012)
DECLARE @dt1 DATETIME = '20120828';
SELECT ISDATE(@dt1);
go




Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Andrew Watson-478275
Andrew Watson-478275
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1677 Visits: 2669
I'm with Hugo on this one that it's a documentation bug on that page. It even states on the very first line of the BOL link provided (their emphasis) "Returns 1 if the expression is a valid date, time or datetime value"

Interestingly though, on the Date/Time functions overview page, it does state "Determines whether a datetime or smalldatetime input expression is a valid date or time value."
(http://msdn.microsoft.com/en-us/library/ms186724).
Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8748 Visits: 11718
I've raised a documentation bug for this issue: https://connect.microsoft.com/SQLServer/feedback/details/759944/documentation-of-isdate-function-incorrect

@Andrew: That part is not actually incorrect, but it is (in my opinion) badly phrased. I would personally prefer to use the words "represents a valid date, time, or datetime value", or "can be converted to date, time, or datetime" to prevent this misunderstanding.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18549 Visits: 13248
Hugo Kornelis (8/28/2012)
I've raised a documentation bug for this issue: https://connect.microsoft.com/SQLServer/feedback/details/759944/documentation-of-isdate-function-incorrect


Voted +1.
(and indicated I could reproduce it)

Very interesting question, thanks.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Jan Van der Eecken
Jan Van der Eecken
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2263 Visits: 6492
Just a question: Why would one want to pass a DATE to ISDATE()? Surely that should always return TRUE, even if it is NULL (which it doesn't if passed a NULL datetime or varchar)?

--------------------------------------------------------------------------
A little knowledge is a dangerous thing (Alexander Pope)

In order for us to help you as efficiently as possible, please read this before posting (courtesy of Jeff Moden)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search