在SQL Server中将dd/mm/yyyy转换为日期 [英] Convert dd/mm/yyyy to date in SQL Server
本文介绍了在SQL Server中将dd/mm/yyyy转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很努力地尝试将字符串类型的列转换为日期.
I'm going nuts trying to convert a string type column into date.
列名称为StartDate
,其中包含字符串日期格式dd/mm/yyyy
.字段类型为varchar(3000)
.
The column name is StartDate
, which contains a string date format dd/mm/yyyy
. The field type is varchar(3000)
.
我尝试了以下操作:
CONVERT(datetime, StartDate, 103)
CAST(CONVERT(VARCHAR(10), StartDate, 110) AS DATE)
CONVERT(DATE, RIGHT(StartDate, 4) + '-' + SUBSTRING(StartDate, 4, 2) + '-' + LEFT(StartDate, 2), 126)
和其他类似组合.
我不断收到超出范围"和转换失败"错误消息.
I keep getting "out of range" and "conversion failed" error messages.
有人有创意的解决方案吗?
Does anyone have a creative solution?
推荐答案
我怀疑您有一些虚假数据.例如
I suspect you have some bogus data. For example
Select try_convert(date, '15/07/2014', 103)
返回
2014-07-15
如果是2012年以后,我建议您
If 2012+, I would suggest that you
Select *
From YourTable
Where try_convert(date, StartDate, 103) is null
这将确定您的问题区域
这篇关于在SQL Server中将dd/mm/yyyy转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文