将INT转换为DATETIME(SQL)

编程入门 行业动态 更新时间:2024-10-25 13:30:01
本文介绍了将INT转换为DATETIME(SQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将日期转换为datetime,但会收到错误。我要转换的数据类型是(float,null),我想将它转换为DATETIME。

I am trying to convert a date to datetime but am getting errors. The datatype I'm converting from is (float,null) and I'd like to convert it to DATETIME.

这段代码的第一行工作正常,但我在第二行获得此错误:

The first line of this code works fine, but I get this error on the second line:

Arithmetic overflow error converting expression to data type datetime. CAST(CAST( rnwl_efctv_dt AS INT) AS char(8)), CAST(CAST( rnwl_efctv_dt AS INT) AS DATETIME),

推荐答案

您需要转换为char第一,因为转换为int添加那些天到1900-01 -01

you need to convert to char first because converting to int adds those days to 1900-01-01

select CONVERT (datetime,convert(char(8),rnwl_efctv_dt ))

这里有一些例子

select CONVERT (datetime,5)

1900-01-06 00:00:00.000

1900-01-06 00:00:00.000

select CONVERT (datetime,20100101)

$ b b

炸开,因为您无法将20100101天添加到1900-01-01..you超过限制

blows up, because you can't add 20100101 days to 1900-01-01..you go above the limit

转换为char first

convert to char first

declare @i int select @i = 20100101 select CONVERT (datetime,convert(char(8),@i))

更多推荐

将INT转换为DATETIME(SQL)

本文发布于:2023-11-04 12:14:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557914.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   INT   SQL   DATETIME

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!