T-SQL

  • aaz (11/20/2009)


    >>Note that in the discussion, there are a number of comments on the question prior to it being edited. Please understand the idea of the question is to understand time zone issues.<<

    This is ****. Question was clear: will date, hour, minutes be the same? As two functions give different results in different timezones results of the queries will differ too. Except UK but we should not expect identical results as this answer suggests.

    It seems that author of this question don't understand timezone issues.

    --

    ptr

    Unfortunately you have missed the point of the question. If you call getdate() and getutcdate() at the "same" time (such that both complete withing the same second), although the values are different they represent the same point in time.

  • >>Will all these statements (...) return an equivalent date, hour, minute and second <<

    Question was about "date, hour, minute and second" returned by the statements, not about "moment in time". I understand that author could have something else on his/her mind but fact is that those statements will generally return different values.

    Question was not referring to the meaning of the results but to the values returned

    --

    ptr

  • aaz (11/20/2009)


    >>Will all these statements (...) return an equivalent date, hour, minute and second <<

    Question was about "date, hour, minute and second" returned by the statements, not about "moment in time". I understand that author could have something else on his/her mind but fact is that those statements will generally return different values.

    Question was not referring to the meaning of the results but to the values returned

    --

    ptr

    Actually it did, if you take into account the time zones, and adjust appropriately; 8:00 AM MST == 3:00 PM UTC.

  • Lynn Pettis (11/20/2009)


    aaz (11/20/2009)


    >>Will all these statements (...) return an equivalent date, hour, minute and second <<

    Actually it did, if you take into account the time zones, and adjust appropriately; 8:00 AM MST == 3:00 PM UTC.

    Nope... I do have the original question posted as below:

    Will all these statements when executed as a batch return the same date, hour, minute and second?

    SELECT DATEADD(day, -1, GETDATE()),DATENAME (dw ,DATEADD(day, -1, GETDATE()) )

    SELECT GETDATE() - 1, DATENAME (dw ,GETDATE() - 1)

    SELECT GETUTCDATE() - 1, DATENAME (dw,GETUTCDATE() - 1)

    SELECT DATEADD(day, -1, GETUTCDATE()), DATENAME (dw,DATEADD(day, -1, GETUTCDATE()))

    GO

    By bitbucket

    SAME (=) is NOT same as EQUIVALENT (==) in this case.

    If the author of QOD posted something like below:

    Will all these statements when executed as a batch return the same date:

    SELECT CONVERT (date, CURRENT_TIMESTAMP)

    SELECT CONVERT (date, GETDATE())

    SELECT CONVERT (date, GETUTCDATE());

    Answer choices:

    a) True in SQL Server 2005, 2008

    b) True in SQL Server 2005 only

    c) True in SQL Server 2008 only and will give error in SQL Server 2005 as "Type date is not a defined system type."

    Then the question snd answer choices are clear.

    Either the question should have been rightly worded or answer choices given properly to eliminate any discripencies of what the question is intending.

    I think most of us already know getdate() and getutcdate() return datetime stamp of local system and GMT datetime respectively.

  • the problem I have with the question is that by context(being posed on a SQL server site) the answer is assumed to be in relationship to SQL server, and as such:

    select case when getdate()=getutcdate() then 'match' else ' no match' end

    should prove that the correct answer is that they do NOT match

    instead the question is written to apply to the physical world, where utc and local are equivalent.

    this is kind of like going to a math class and asking what is 1+1

    everyone who answers 2 is wrong, since i was asking the question in base2, not base10, so the answer would of course be 10, can't you all see how wrong it was to pick 2? It's amazing the number of people who don't understand simple addition.

    The context of the question is as important as the question itself, and in this I think the question fell short.

    David



    If you haven't made it to PASS Summit, do so.
    The knowledge and networking available there is amazing.
    Bring a kilt.

  • David Easley-401108 (11/20/2009)


    this is kind of like going to a math class and asking what is 1+1

    everyone who answers 2 is wrong, since i was asking the question in base2, not base10, so the answer would of course be 10, can't you all see how wrong it was to pick 2? It's amazing the number of people who don't understand simple addition.

    David

    You are right!

    Imagine another teacher who thinks about logics, and now 1+1 = 1.

    Do you know how many people don't think logically?

    🙂



    See, understand, learn, try, use efficient
    © Dr.Plch

  • rparakalla (11/20/2009)


    Lynn Pettis (11/20/2009)


    aaz (11/20/2009)


    >>Will all these statements (...) return an equivalent date, hour, minute and second <<

    Actually it did, if you take into account the time zones, and adjust appropriately; 8:00 AM MST == 3:00 PM UTC.

    Nope... I do have the original question posted as below:

    Will all these statements when executed as a batch return the same date, hour, minute and second?

    SELECT DATEADD(day, -1, GETDATE()),DATENAME (dw ,DATEADD(day, -1, GETDATE()) )

    SELECT GETDATE() - 1, DATENAME (dw ,GETDATE() - 1)

    SELECT GETUTCDATE() - 1, DATENAME (dw,GETUTCDATE() - 1)

    SELECT DATEADD(day, -1, GETUTCDATE()), DATENAME (dw,DATEADD(day, -1, GETUTCDATE()))

    GO

    By bitbucket

    SAME (=) is NOT same as EQUIVALENT (==) in this case.

    If the author of QOD posted something like below:

    Will all these statements when executed as a batch return the same date:

    SELECT CONVERT (date, CURRENT_TIMESTAMP)

    SELECT CONVERT (date, GETDATE())

    SELECT CONVERT (date, GETUTCDATE());

    Answer choices:

    a) True in SQL Server 2005, 2008

    b) True in SQL Server 2005 only

    c) True in SQL Server 2008 only and will give error in SQL Server 2005 as "Type date is not a defined system type."

    Then the question snd answer choices are clear.

    Either the question should have been rightly worded or answer choices given properly to eliminate any discripencies of what the question is intending.

    I think most of us already know getdate() and getutcdate() return datetime stamp of local system and GMT datetime respectively.

    You know, I have never tried to write a QotD. I understand it is difficult to write one such that it tests ones knowledge without giving away the answer when you have people from newbies to gurus trying to answer the question.

    Okay, the question may have had some issues, I'll give everyone that. But the point of the question wasn't does GETDATE() = GETUTCDATE(). The point really was do the represent the same point in time when executed together in a single batch that completed within the same second (ignore the differences in milliseconds).

  • Lynn, the intention of the author when executed as a batch was totally lost by mentioning

    "....same date hour, minute and second?"

    It is not even like looking at the half filled glass and debating is it half empty / is it half full

    🙂

  • Please refrain from profanity. It doesn't add to the discussion and it is not professional.

    I have changed the question to have 1 answer and added a note about the debate. I'm also closing this thread now since I think both points have been made.

Viewing 9 posts - 196 through 203 (of 203 total)

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