Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
750 views
in Technique[技术] by (71.8m points)

sql-server - SQL Server字符串到日期的转换(Sql Server string to date conversion)

I want to convert a string like this:

(我想这样转换一个字符串:)

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

into the equivalent DATETIME value in Sql Server.

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

In Oracle, I would say this:

(在Oracle中,我会这样说:)

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?

(有没有更简单的方法?)

  ask by JosephStyons translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this

(尝试这个)

Cast('7/7/2011' as datetime)

and

(和)

Convert(varchar(30),'7/7/2011',102)

See CAST and CONVERT (Transact-SQL) for more details.

(有关更多详细信息,请参见CAST和CONVERT(Transact-SQL) 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...