将 Int 转换为日期字段 [英] Convert an Int to a date field
本文介绍了将 Int 转换为日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将整数字段转换为实际日期字段.有人创建了一个日期"字段,它只是插入一个实际上是一个整数的日期".我正在尝试将其转换为实际日期.
I'm trying to convert an integer field to an actual date field. Someone created a "date" field that just sticks in a "date" that is actually an integer. I'm trying to convert it to an actual date.
我尝试了以下方法无济于事:
I have tried the following to no avail:
CAST(CAST(last_purch_date AS CHAR) AS DATE) as Create,
CAST( last_purch_date as datetime) as Created,
convert(datetime,last_purch_date) as Created1,
ISDATE(CONVERT(CHAR(8),last_purch_date)) as PleaseDearGodWORK
推荐答案
Simple cast as date 可以工作
Simple cast as date could work
Select cast(cast(20161011 as varchar(8)) as date)
退货
2016-10-11
如果您的数据可疑,您也可以使用 Try_Convert()
If your data is suspect, you could also use Try_Convert()
Select Try_Convert(date,cast(2610 as varchar(8)))
退货
NULL
这篇关于将 Int 转换为日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文