[英]How to convert string format “yyyyMMdd HHmmss_fff” to date T-SQL?
I'm getting this string "20150930 092622_647" and have to save it to a datetime column but I can convert it. 我得到这个字符串“20150930 092622_647”,并且必须将它保存到日期时间列,但我可以将其转换。
I know about the CONVERT but the closest expression style I found was 112 the problem is the time not the date here. 我知道CONVERT,但我找到的最接近的表达方式是112问题是时间不是这里的日期。
CONVERT(DATETIME, REPLACE( '20150930 092622_647', '_', ' '), 112)
You don't need the style unless you are converting the other way... from a datetime
to a character based type. 除非您正在转换另一种方式...从
datetime
到基于字符的类型,否则您不需要样式。
This expression will probably get you what you need: 这个表达式可能会得到你所需要的:
select convert(datetime,stuff(stuff(stuff('20150930 092622_647',16,1,'.'),14,0,':'),12,0,':'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.