将Varchar转换为日期时间 [英] Converting Varchar to datetime

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

问题描述



谁能告诉我执行该错误的原因:

 选择 >转换( 102 )
 FROM  Table1 


这里dob Varchar(10)
日期采用dd/mm/yyyy(5/24/1995)格式

在此先感谢...

解决方案

日期为dd/mm/yyyy(5/24/1995)格式


1995年5月24日是m/d/yyyy格式.

以下作品很好

 选择 转换(日期时间'  5/24/1995' 102 ) AS  Expr1 



 选择 转换(日期时间,dob, 102 )来自 testTable 



确保所有行中都有正确的数据.您究竟会遇到什么错误?


没有看到您的数据,很难确定,但是我认为"dob"字段未包含正确格式的日期信息:即由"102"样式参数指定的"yyyy.MM.dd"


Hi,

Can anyone tell me why the error occurs when executing:

SELECT  CONVERT(Datetime,dob,102)
FROM    Table1


Here dob is Varchar(10)
Date is in dd/mm/yyyy(5/24/1995) format

Thanks in advance...

解决方案

Date is in dd/mm/yyyy(5/24/1995) format



5/24/1995 is m/d/yyyy format.

Following works fine

SELECT CONVERT(datetime, '5/24/1995', 102) AS Expr1


and

SELECT CONVERT(datetime, dob, 102) from testTable



Make sure you have proper data in all rows. What error you get exactly?


Without seeing your data, it is difficult to be sure, but I would assume that the "dob" field does not contain date information in the correct format: i.e. "yyyy.MM.dd" as specified by the "102" style parameter


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

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