【发布时间】:2013-02-04 12:33:41
【问题描述】:
我有一个表,其中 DATEDEPOT 列为 varchar(20)。
里面的信息是这样的:20020101 - 我的意思是YYYYMMDD
我想把它转换成日期时间。
为此,我检查了其他帖子的答案,但对我没有任何帮助。
这是我尝试过的:
select datedepot, cast(datedepot as datetime) as test from DessinsV2
我收到这条消息:
Msg 241,Niveau 16,État 1,Ligne 1。
Échec de la conversion de la date et/ou de l'heure à partir d'une chaîne de caractères。
我试过了:
declare @Madate char(10)
SELECT @MaDate=datedepot from DessinsV2
select convert(datetime,left(@Madate,4)+substring(@Madate,5,2)+right(@Madate,2))as DATEDEPOTTEST from dessinsv2
我得到:
Msg 241,Niveau 16,État 1,Ligne 1
Échec de la conversion de la date et/ou de l'heure à partir d'une chaîne de caractères。
【问题讨论】:
-
你使用哪个数据库?
-
这个问题需要(需要)一个 SQL 引擎标签(MySQL、PostgreSQL 等),但尽管要求澄清,但仍未提供。我现在会尝试将其标记为缺少minimal reproducible example,但如果它已关闭,它肯定可以在编辑后再次重新打开。
标签: sql type-conversion