isdate 和新西兰返回 false

isdate and new zealand returning false(isdate 和新西兰返回 false)

本文介绍了isdate 和新西兰返回 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题来了:

select ISDATE('2012-06-21 4:11 P.M.') 

文化是 en-NZ(新西兰),上面的字符串日期是他们格式化日期的方式.

The culture is en-NZ (New Zealand) and the string date above is how they format their dates.

在这种情况下,我如何使 ISDATE 为真?

How do I make ISDATE true in this case?

推荐答案

理想情况下,您可以更好地控制字符串格式.如果您以标准格式传递,则不应关心文化是 EN-NZ 还是其他文化,例如:

Ideally you would control the string format better than that. You shouldn't care whether the culture is EN-NZ or anything else if you pass in a standard format, such as:

SELECT ISDATE('20120621 16:11'); -- will never fail regardless of locale/language/DMY

如果您需要允许人们以他们希望的任何格式输入日期,那么您必须以各种方式处理它.例如:

If you need to allow people to enter dates in any format they wish, then you have to deal with it in various ways. For example:

SELECT ISDATE(CONVERT(DATETIME, REPLACE('2012-06-21 4:11 P.M.', '.', ''), 120));

这篇关于isdate 和新西兰返回 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:isdate 和新西兰返回 false

基础教程推荐