ISDATE (TSQL Function)

Returns 1 if the string expression can be parsed as date, time, or datetime. Else, returns 0.

Syntax

ISDATE ( string_expression )

Arguments

string_expression
is an expression of type varchar.

Return Types

Returns int.

Remarks

The result depends on the current DATEFORMAT settings.

This setting can be modified with SET LANGUAGE or SET DATEFORMAT.

If string_expression is NULL, the function returns 0.

Examples

SET LANGUAGE en_US; -- DATEFORMAT is mdy

PRINT '--- current language is ' + @@LANGUAGE
PRINT ISDATE('04-15-2016'); -- returns 1
PRINT ISDATE('04.15.2016'); -- returns 1
PRINT ISDATE('04/2016/15'); -- returns 0
PRINT ISDATE('15/04/2016'); -- returns 0

SET LANGUAGE fr_FR; -- DATEFORMAT is dmy

PRINT '--- current language is ' + @@LANGUAGE
PRINT ISDATE('04-15-2016'); -- returns 0
PRINT ISDATE('04.15.2016'); -- returns 0
PRINT ISDATE('04/2016/15'); -- returns 0
PRINT ISDATE('15/04/2016'); -- returns 1

The result is:

--- current language is en-US
1
1
0
0
--- current language is fr-FR
0
0
0
1