More Precedence

  • Avinash

    Grasshopper

    Points: 12

    Comments posted to this topic are about the item More Precedence

  • Stewart "Arturius" Campbell

    SSC Guru

    Points: 71938

    That is really interesting.
    Pity this cannot be effected on the new  datetime datatypes (e.g. datetime2)
    thanks for the question, Avinash

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    β€œlibera tute vulgaris ex”

  • Mighty

    SSCrazy Eights

    Points: 8869

    Is there an explanation why 0x20 (32) results in 107 milliseconds?

  • Thomas Rushton

    SSC-Insane

    Points: 22648

    Mighty - Tuesday, November 7, 2017 1:47 AM

    Is there an explanation why 0x20 (32) results in 107 milliseconds?

    Spoiler:
    Ë™sɯㄥ0Æ– xoɹddÉ sá´‰ Çsoɥʇ ÉŸo á„…Æ ;puoÉ”Çs É ÉŸo ɥʇ00Æ/Æ– sá´‰ ÇdʎʇÉʇÉp ÇɯᴉʇÇʇÉp Çɥʇ uá´‰ Çɯᴉʇ ÉŸo uoá´‰sᴉʌᴉpqns ʇsÇllÉɯs Çɥ┴

    Thomas Rushton
    blog: https://thelonedba.wordpress.com

  • Mighty

    SSCrazy Eights

    Points: 8869

    ThomasRushton - Tuesday, November 7, 2017 4:21 AM

    Mighty - Tuesday, November 7, 2017 1:47 AM

    Is there an explanation why 0x20 (32) results in 107 milliseconds?

    Spoiler:
    Ë™sɯㄥ0Æ– xoɹddÉ sá´‰ Çsoɥʇ ÉŸo á„…Æ ;puoÉ”Çs É ÉŸo ɥʇ00Æ/Æ– sá´‰ ÇdʎʇÉʇÉp ÇɯᴉʇÇʇÉp Çɥʇ uá´‰ Çɯᴉʇ ÉŸo uoá´‰sᴉʌᴉpqns ʇsÇllÉɯs Çɥ┴

    That spoiled it! πŸ˜‰

  • Budd

    Hall of Fame

    Points: 3769

    Adding a binary value to datetime is not the same as adding an integer value. - this I know.
    Adding 32 to datetime adds 32 days
    Adding x20 to datetime adds 107 milliseconds
    WHY - THAT I DON'T KNOW, YET!!

  • Lynn Pettis

    SSC Guru

    Points: 442360

    Because it isn't adding 32 to the date time value:

    NewDate                 DateAsBinary                                                       NewDateAsBinary
    ----------------------- ------------------------------------------------------------------ ------------------------------------------------------------------
    2001-01-01 00:00:00.107 0x0000901A00000000                                                 0x0000901A00000020

  • Budd

    Hall of Fame

    Points: 3769

    That I can understand.  However πŸ™‚
    Where is the logic in doing a calculation in a different datatype than what the result will be displayed as?

  • Budd

    Hall of Fame

    Points: 3769

    OH and BTW thank you for your answer.

  • Ed Wagner

    SSC Guru

    Points: 286988

    I enjoy date math.  Thomas explained the answer above.

    If you add an integer to a datetime data type, it adds that number of days and returns the correct datetime.  This meets the standard of date + interval = new date.

    Not so with datetime2.  It gives an operand type clash error.
    The one that really gets me is the date data type.  It gives the same error.

    Microsoft did a lot of things right with the datetime type, but missed the boat with the newer ones.  I don't know why they made the decisions they did.
    DATEADD works with both, but not straight addition and subtraction.

  • Jeff Moden

    SSC Guru

    Points: 997319

    Budd - Tuesday, November 7, 2017 12:00 PM

    That I can understand.  However πŸ™‚
    Where is the logic in doing a calculation in a different datatype than what the result will be displayed as?

    In this particular case (binary level), probably nothing other than finding out if you actually know how the DATETIME datatype works.  In real life, I use direct date math a lot (but not at the binary level).

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".
    "Dear Lord... I'm a DBA so please give me patience because, if you give me strength, I'm going to need bail money too!"

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 11 posts - 1 through 11 (of 11 total)

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