Is there a function like isdate() for datetime2?
问题 I know there is a function called ISDATE to validate DATETIME columns, but it works only for the SMALLDATETIME and DATETIME types. Is there a similar way to validate the new data type DATETIME2 in SQL Server 2008 and 2012? 回答1: In SQL Server 2012, you can use TRY_CONVERT : SELECT TRY_CONVERT(DATETIME2, '2012-02-02 13:42:55.2323623'), TRY_CONVERT(DATETIME2, '2012-02-31 13:42:55.2323623'); Results: 2012-02-02 13:42:55.2323623 NULL Or TRY_PARSE : SELECT TRY_PARSE('2012-02-02 13:42:55.2323623' AS