• Michael Valentine Jones (11/2/2010)


    timothy bates (11/2/2010)


    Accurate question. I think any question that uses a date with obvious notation to remove all ambiguity such as '2010-Jan-01' is fine. We clearly understand which is the year, month, and day. '201000205' while most would consider it to be February 5, 2010; 5 February 2010; or 2010 Februrary 5 it isn't perfectly clear.

    I would have liked to seen this instead:

    DATEADD(MONTH, 1, '2010-Jan-30')

    Feb 28 is correct not Feb 27 day preceeding end of month nor March 1 30 days post Jan 30.

    Tim

    The problem with '2010-Jan-01' is that it is not even a valid date with many or most language settings.

    set language italian;

    select DT = convert(datetime,'2010-Jan-01')

    Result:

    L'impostazione della lingua è stata sostituita con Italiano.

    Server: Msg 241, Level 16, State 1, Line 3

    Conversione non riuscita durante la conversione di una stringa di caratteri nel tipo di dati datetime.

    '201000205' is perfectly clear to SQL Server. It will only interpret it one way, as YYYYMMDD, no matter what the setting of LANGUAGE or DATEFORMAT.

    Actually there is an error. One too many 0's between the 1 and second 2 (mine but I am getting picky now).

    As long as the intent is clear and ambiguity can't be inferred I am fine with however it is posted. I don't execute QOTD questions to determine my answer. I work through it as though I am reviewing a printout of code or taking an exam. I assume (wrongly at times) that dates are shown to be compliant with the posters environment but may not be with mine. If someone posted a question with a date '2010-Juli-06'. I would assume it works with the local install. I haven't had to account for backup/failover servers installed in separate countries as part of a disaster recovery/business continuity plan (yet). Of course this could be a whole separate question.

    Maybe all questions should include the Set Language command to remove all possible ambiguity or something like:

    declare @dt as datetime

    select @dt = <an acceptable date format for January 3, 2012>

    select dateadd(mm,2,@dt) as two_months_later

    Tim