• Good question, was also misdirected by BOL but kept my option and got it right.

    I also +1 to Hugo's submission, I hope Microsoft fixes it quick.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • Hugo Kornelis (8/28/2012)

    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 ( 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);


    -- Show that datetime will work in ISDATE (even on SQL 2008 and SQL 2012)

    DECLARE @dt1 DATETIME = '20120828';

    SELECT ISDATE(@dt1);



    Jason...AKA CirqueDeSQLeil
    I have given a name to my pain...MCM SQL Server, MVP
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Great question. It seems counterintuitive that ISDATE would not work for a date data type since it works for datetime. But I am not sure why you would ever need to do that.

  • Thanks all for the great question and other interesting forum posts.

    Makes a good read.

    [font="Comic Sans MS"]"The difficult tasks we do immediately, the impossible takes a little longer"[/font]

  • Koen Verbeeck (8/28/2012)

    Hugo Kornelis (8/28/2012)

    I've raised a documentation bug for this issue:

    Voted +1.

    (and indicated I could reproduce it)

    Very interesting question, thanks.



Viewing 5 posts - 16 through 19 (of 19 total)

You must be logged in to reply to this topic. Login to reply