Don't forget this date.

  • SanjayAttray (4/2/2010)


    The ultimate guide to the datetime datatypes

    http://www.karaszi.com/SQLServer/info_datetime.asp#Why1753

    Sanjay,

    Thank you for the excellent reference, and its explanation of "Why 1753".

    -c

  • Hi all,

    This is an extrapolated question from the actual QoD, but I would like to know the reason (coz of knowledge gaining reason)

    Why the 'mmm' part in the RESULT section giving a different value than I entered through the character string as shown below.

    SET DATEFORMAT MDY

    DECLARE @dmy datetime

    SELECT @dmy = '12/31/99 12:13:12:012'

    SELECT @dmy

    RESULT:

    1999-12-31 12:13:12.013

    Thanks

    big[M]

    John

  • bigM (4/2/2010)


    Hi all,

    This is an extrapolated question from the actual QoD, but I would like to know the reason (coz of knowledge gaining reason)

    Why the 'mmm' part in the RESULT section giving a different value than I entered through the character string as shown below.

    SET DATEFORMAT MDY

    DECLARE @dmy datetime

    SELECT @dmy = '12/31/99 12:13:12:012'

    SELECT @dmy

    RESULT:

    1999-12-31 12:13:12.013

    Thanks

    big[M]

    The accuracy of datetime is not to the millisecond, but to 1/300 of a second. So each second is divided into 300 slices of 3 1/3 milliseconds. And because display uses milliseconds, you see the values rounded to the millisecond: 0.000, 0.003, 0.007, 0.010, 0.013, 0.017, .....


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Paul White NZ (4/2/2010)


    I wonder how long it will be before someone complains that this QotD is misleading and incorrect since the question specifies "(yyyy/mm/dd)" format and the answers are all in YYYY-MM-DD format?

    :laugh:

    Surprised it hasn't happened yet.

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

  • Nice question.

    Thanks

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

  • Voitek (4/2/2010)


    I did a cast(0 as datetime), but then I thought hmm. can negatives be converted to datetime? I picked 64000, but that failed, so then I went incrementally to -53690 beyond which the cast fails.

    I don't think the QOD is misleading. The oldest date you can store is -53690, which is 1-1-1753.

    Nice information. Thanks for providing it.

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

  • CirquedeSQLeil (4/2/2010)


    Surprised it hasn't happened yet.

    vk-kirov covered it!

  • Paul White NZ (4/2/2010)


    CirquedeSQLeil (4/2/2010)


    Surprised it hasn't happened yet.

    vk-kirov covered it!

    I found that comment funny.

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

  • I found this one fairly easy. Good discussion, which adds to question.

  • I didn't knew it.. Great one to know...

  • This is a very interesting question, thank you Carla. I knew that 1753-01-01 was selected as the first available date, but had no clue why the SQL Server team chose it. The number -53690 does not appear to be of any significance, so I learned something new today.

    Oleg

  • same with me ...whenever i selects date columns it shows same..

  • Lynn Pettis (4/2/2010)


    I found this one fairly easy. Good discussion, which adds to question.

    I have to admit, I did not find this one as easy. I did have to do some checking and research.

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

  • Any idea what the latest date is? I got as far as 500,000 days into the future before i gave up, I doubt i'd have much use for this unless i'm using DBCC timewarp though 🙂

  • From MS SQL documentation:

    datetime: January 1, 1753, through December 31, 9999

    smalldatetime: January 1, 1900, through June 6, 2079

    Note:

    datetime is stored as two 4-byte integers for days from 1/1/1900 and milliseconds since midnight.

    smalldatetime is stored as two 2-byte integers for days from 1/1/1900 and minutes since midnight.

Viewing 15 posts - 16 through 30 (of 33 total)

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