Shivpe_R
Shivpe_R

Reputation: 1080

Convert Numeric to Date in MS SQL

There is already a Datecolumn in Table which is in Numeric DataType(Converted to Int for faster ODBC Transfer), How can i convert that number to Data again?

Example the Values are like

42508
42826
43191
42158
42527

Which are nothing but like

SELECT CONVERT(numeric, getdate())

Query Result

43571

Just want to know how can i convert back that to normal date ?

Upvotes: 0

Views: 275

Answers (1)

Zhorov
Zhorov

Reputation: 29993

You may use next conversion:

SELECT CONVERT(date, DATEADD(day, 43570, 0))

which will output:

17/04/2019 00:00:00

In this case SQL Server will use implicit data type conversion, because DATEADD() allows datetime datatype as third parameter and DATEADD() will convert 0 to 1900-01-01.

Upvotes: 4

Related Questions