[英]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? 表中已经有一个日期列,该日期列为数字DataType(为了更快的ODBC传输而转换为Int),如何再次将该数字转换为Data?
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
. 在这种情况下,SQL Server将使用隐式数据类型转换 ,因为DATEADD()允许将datetime
数据类型用作第三个参数,而DATEADD()
会将0
转换为1900-01-01
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.