The Time Zone Range

  • Comments posted to this topic are about the item The Time Zone Range

  • I think the question is not correct and the answer should be "datetime2 doesn't aware of time zone offset".

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • There are 2 answers here that are correct, it just depends on what you choose. The answer shown as correct is rightly so, but the answer that states that the datetime2 does not store the time zone is also correct.

    If your only answer is what value is stored/shown then a is correct and I have not read the question correct.

     

  • The datetime2 isn't aware of time zones, nor does it store them. Once this is stored, there is no +00:00, so that is not correct.

  • The question is a bit misleading - as it mentions a concern about the time zone (which isn't actually part of the string - the string contains an offset which isn't the same as a time zone).

    A more correct answer would be to change the data type from datetime2 to datetimeoffset.  That would retain the offset and no loss of data would occur.  However, the question was about what the result of the statement would be - and not what would resolve the issue of losing the offset (time zone) value.

    Answer D is not correct - because SQL Server will implicitly convert the string to a datetime2 data type and truncate the offset.  Worse is the fact that the value of the conversion is now incorrect - as it is the value *after* applying the offset and not the true UTC value.

     

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • The question is about knowing datetime2 doesn't contain the time zone, not how to convert to a different datatype.

  • Steve Jones - SSC Editor wrote:

    The question is about knowing datetime2 doesn't contain the time zone, not how to convert to a different datatype.

    The question is misleading:

    I need to assign this value from a string that looks like this: '2020-01-10 16:00:00 -07:00' When I do this, I am concerned that I might lose the time zone value. What value is @date assigned?

    The question states they are concerned they might lose the time zone value (offset) - then asks what value is @date assigned.  There is no requirement to even mention being concerned about loss of the time zone (offset) if the only point of the question is to determine the value of @date.

    The correct answer to the question 'What value is @date assigned?' is option A - all other options are incorrect.

    With that said - the correct answer to the implied question relating to loss of time zone (offset) is to not use a datetime2 data type - rather the solution to that implied portion of the question would be to use datetimeoffset.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 9 posts - 1 through 8 (of 8 total)

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