在T-SQL中将文本格式的日期转换为日期时间格式 [英] Convert date in text format to datetime format in T-SQL

查看:864
本文介绍了在T-SQL中将文本格式的日期转换为日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端提供的文件,该文件已加载到我们的SQL Server数据库中。该文件包含基于文本的日期值,即(05102010),作为清理的一部分,我需要从数据库列中读取它们并将其转换为正常的日期时间值='2010-05-10 00:00:00.000'处理。

I have a client supplied file that is loaded in to our SQL Server database. This file contains text based date values i.e. (05102010) and I need to read them from a db column and convert them to a normal date time value = '2010-05-10 00:00:00.000' as part of a clean-up process.

任何指导将不胜感激。

推荐答案

使用

CONVERT(datetime,RIGHT(Column,4) + left(Column,4))

示例

declare @s char(8)
select  @s = '05102010'
select CONVERT(datetime,RIGHT(@s,4) + left(@s,4))

这篇关于在T-SQL中将文本格式的日期转换为日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆