SQL Server字符串到日期的转换 [英] Sql Server string to date conversion

查看:956
本文介绍了SQL Server字符串到日期的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换这样的字符串:

I want to convert a string like this:

'10/15/2008 10:06:32 PM'

转换为Sql Server中的等效DATETIME值。

into the equivalent DATETIME value in Sql Server.

在Oracle中,我会这样说:

In Oracle, I would say this:

TO_DATE('10/15/2008 10:06:32 PM','MM/DD/YYYY HH:MI:SS AM')

此问题表示我必须将字符串解析为标准格式,然后使用这些代码之一进行转换。对于这种平凡的行动来说,这似乎很可笑。有没有更简单的方法?

This question implies that I must parse the string into one of the standard formats, and then convert using one of those codes. That seems ludicrous for such a mundane operation. Is there an easier way?

推荐答案

SQL Server(2005、2000、7.0)没有任何灵活性,甚至没有灵活的方式,它以字符串格式获取任意结构化的datetime并将其转换为datetime数据类型。

SQL Server (2005, 2000, 7.0) does not have any flexible, or even non-flexible, way of taking an arbitrarily structured datetime in string format and converting it to the datetime data type.

任意是指写了它,尽管也许不是您,我或地球另一端的人会认为是直觉的,而且完全显而易见。坦白说,我不确定是否有这种算法。

By "arbitrarily", I mean "a form that the person who wrote it, though perhaps not you or I or someone on the other side of the planet, would consider to be intuitive and completely obvious." Frankly, I'm not sure there is any such algorithm.

这篇关于SQL Server字符串到日期的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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