isdate and new zealand returning false

2019-08-23 04:25发布

问题:

Here the problem:

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

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

How do I make ISDATE true in this case?

回答1:

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));


回答2:

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

this link is a useful one in your case

http://jefferychinet.blogspot.com/2009/02/sql-server-2005-change-datetime-format.html