SQL Server ISDATE() Function

The ISDATE() function in SQL Server is a valuable tool for validating whether a given expression can be interpreted as a valid date.



ISDATE(): Definition and Usage

This function is particularly useful when dealing with data imported from external sources or user inputs where you need to ensure that date values are correctly formatted and within an acceptable range before processing or storing them in your database.

Syntax

Syntax

ISDATE(expression)
      

Parameter Values

Parameter Description
expression The expression you want to check for date validity. This can be a literal string, a column name, or any other expression that could potentially represent a date. This is required.

Examples

Checking a Valid Date

This example checks if '2017-08-25' is a valid date. ISDATE() returns 1 (true) if it is, and 0 (false) otherwise.

Syntax

SELECT ISDATE('2017-08-25');
      
Output

1
      

Checking an Invalid Date

This example tests an invalid date format. The output will be 0.

Syntax

SELECT ISDATE('2017');
      
Output

0
      

Checking Non-Date Text

This example shows that non-date text is correctly identified as invalid.

Syntax

SELECT ISDATE('Hello world!');
      
Output

0
      

Technical Details

Return Type: int (integer)

Works in:

  • SQL Server (starting with version 2008)
  • Azure SQL Database
  • Azure SQL Data Warehouse
  • Parallel Data Warehouse