# Convert smallint to Date

• PJ_SQL

SSCertifiable

Points: 6594

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: 25841

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: 995643

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

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

• Jeff Moden

SSC Guru

Points: 995643

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