Convert smallint to Date

  • PJ_SQL

    SSCertifiable

    Points: 6403

    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.

  • Michael L John

    One Orange Chip

    Points: 25717

    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/

  • Jeff Moden

    SSC Guru

    Points: 994279

    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.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

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

  • Jeff Moden

    SSC Guru

    Points: 994279

    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.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

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

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

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