我在varchar中有一列日期,我需要转换为日期 [英] I have a column of dates in varchar and i need to convert to date
本文介绍了我在varchar中有一列日期,我需要转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
日期当前显示为: ddmmmyyyy
(12DEC2013)
The dates are currently displayed as: ddmmmyyyy
(12DEC2013)
我一直在玩这个游戏公式:
I've been playing around with this formula:
DECLARE @Date char(8)
set @Date='12312009'
SELECT CONVERT(datetime,RIGHT(@Date,4)+LEFT(@Date,2)+SUBSTRING(@Date,3,2))
,但我没有成功,有人可以帮我这个忙。另外,我所有的日期都在名为 TERMDT
的列中,我想将所有新的日期值放在这样格式化的新列中。
but I didn't have any success, can someone help me out with this. Additionally all my dates are in a column called TERMDT
and I'd like to put all the new date values in a new column formatted as such.
推荐答案
只需给 convert()
一个适当的第三个参数(格式):
Just give convert()
an appropriate 3rd argument (the format):
SELECT CONVERT(datetime,
RIGHT(d, 4) + LEFT(d,2) + SUBSTRING(d, 3, 2),
112)
from (select '12312009' as d) t
这篇关于我在varchar中有一列日期,我需要转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文