Convert smallint to Date

  • Hello!

    I have column in SQL 2012 DB of datatype smallint.

    Could you please let me know how to convert smallint to date?

    Here's the example of smallint data "12940".

     

    Thanks.

  • PJ_SQL wrote:

    Hello! I have column in SQL 2012 DB of datatype smallint. Could you please let me know how to convert smallint to date? Here's the example of smallint data "12940".   Thanks.

     

    What date does 12940 convert to?

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/

  • Assuming that the date occurred in the past...

    If that number is supposed to represent '2005-06-06', then the conversion formula is ...

     SELECT DATEADD(dd,12940,'1970');

    If it's supposed to represent '2015-06-06', then the conversion formula is ...

     SELECT DATEADD(dd,12940,'1980');

    Both 1970 and 1980 we're the start dates of commonly used epochs.

    If neither conversion works for you then, like Michael John stated, we need an example of what a given number would convert to.

    --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.


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

  • So... enquiring minds want to know... did that work or what???

    --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.


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

Viewing 4 posts - 1 through 3 (of 3 total)

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