简体   繁体   中英

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 ?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM