- SQL Tutorial
- SQL - Home
- SQL - Overview
- SQL - RDBMS Concepts
- SQL - Databases
- SQL - Syntax
- SQL - Data Types
- SQL - Operators
- SQL - Expressions
- SQL Database
- SQL - Create Database
- SQL - Drop Database
- SQL - Select Database
- SQL - Rename Database
- SQL - Show Databases
- SQL - Backup Database
- SQL Table
- SQL - Create Table
- SQL - Show Tables
- SQL - Rename Table
- SQL - Truncate Table
- SQL - Clone Tables
- SQL - Temporary Tables
- SQL - Alter Tables
- SQL - Drop Table
- SQL - Delete Table
- SQL - Constraints
- SQL Queries
- SQL - Insert Query
- SQL - Select Query
- SQL - Select Into
- SQL - Insert Into Select
- SQL - Update Query
- SQL - Delete Query
- SQL - Sorting Results
- SQL Views
- SQL - Create Views
- SQL - Update Views
- SQL - Drop Views
- SQL - Rename Views
- SQL Operators and Clauses
- SQL - Where Clause
- SQL - Top Clause
- SQL - Distinct Clause
- SQL - Order By Clause
- SQL - Group By Clause
- SQL - Having Clause
- SQL - AND & OR
- SQL - BOOLEAN (BIT) Operator
- SQL - LIKE Operator
- SQL - IN Operator
- SQL - ANY, ALL Operators
- SQL - EXISTS Operator
- SQL - CASE
- SQL - NOT Operator
- SQL - NOT EQUAL
- SQL - IS NULL
- SQL - IS NOT NULL
- SQL - NOT NULL
- SQL - BETWEEN Operator
- SQL - UNION Operator
- SQL - UNION vs UNION ALL
- SQL - INTERSECT Operator
- SQL - EXCEPT Operator
- SQL - Aliases
- SQL Joins
- SQL - Using Joins
- SQL - Inner Join
- SQL - Left Join
- SQL - Right Join
- SQL - Cross Join
- SQL - Full Join
- SQL - Self Join
- SQL - Delete Join
- SQL - Update Join
- SQL - Left Join vs Right Join
- SQL - Union vs Join
- SQL Keys
- SQL - Unique Key
- SQL - Primary Key
- SQL - Foreign Key
- SQL - Composite Key
- SQL - Alternate Key
- SQL Indexes
- SQL - Indexes
- SQL - Create Index
- SQL - Drop Index
- SQL - Show Indexes
- SQL - Unique Index
- SQL - Clustered Index
- SQL - Non-Clustered Index
- Advanced SQL
- SQL - Wildcards
- SQL - Comments
- SQL - Injection
- SQL - Hosting
- SQL - Min & Max
- SQL - Null Functions
- SQL - Check Constraint
- SQL - Default Constraint
- SQL - Stored Procedures
- SQL - NULL Values
- SQL - Transactions
- SQL - Sub Queries
- SQL - Handling Duplicates
- SQL - Using Sequences
- SQL - Auto Increment
- SQL - Date & Time
- SQL - Cursors
- SQL - Common Table Expression
- SQL - Group By vs Order By
- SQL - IN vs EXISTS
- SQL - Database Tuning
- SQL Function Reference
- SQL - Date Functions
- SQL - String Functions
- SQL - Aggregate Functions
- SQL - Numeric Functions
- SQL - Text & Image Functions
- SQL - Statistical Functions
- SQL - Logical Functions
- SQL - Cursor Functions
- SQL - JSON Functions
- SQL - Conversion Functions
- SQL - Datatype Functions
- SQL Useful Resources
- SQL - Questions and Answers
- SQL - Quick Guide
- SQL - Useful Functions
- SQL - Useful Resources
- SQL - Discussion
SQL - ISDATE() Function
The SQL ISDATE() function allows you to determine whether a value is a valid date. This function will always return the same result if you use it with the convert function. ISDATE() functions return the integer value 1, indicating that the input expression is a valid date; if they return the integer value 0, it indicates that the input expression is not a date.
The ISDATE() function returns 0, If you provide a datetime2 value, informing you that it is not a date.
Syntax
Following is the syntax for the SQL ISDATE() function −
ISDATE(expression)
Parameters
This function accepts only one parameter as discussed below −
expression − the expression that to be checked.
Note − If the given date contains only a time part the month() function returns 1.
Example
In the following query, we are checking whether the expression is valid or not −
SELECT ISDATE('2023-02-16');
Output
When we execute the above query, the output is obtained as follows −
+---------+ | no name | +---------+ | 1 | +---------+
Example
Here, we are trying to find the given expression is valid or not using the following query −
SELECT ISDATE('Tutorialspoint');
Output
On executing the above query, the output is displayed as follows −
+---------+ | no name | +---------+ | 0 | +---------+
Example
The ISDATE() function will return 0 when the parameter is NULL, indicating that the NULL value is not a valid date.
In the following example we are going to use null to check whether the expression is valid or not by executing the below query −
SELECT ISDATE(NULL) as Result;
Output
The output for the above query is produced as given below −
+--------+ | Result | +--------+ | 0 | +--------+
Example
Look at the following example, where we are using the literal name of the month in the expression to check whether the expression is valid or not by using the following query −
SELECT ISDATE('November 27 2000') as Result;
Output
If we execute the above query, the result is produced as follows −
+--------+ | Result | +--------+ | 1 | +--------+
Example
Considering the following example, where we are using the time as an input parameter and checking whether the expression is valid or not by running the following query.
SELECT ISDATE('2:36:00') as Result;
Output
On executing the above query, it will generate the following output as shown below −
+--------+ | Result | +--------+ | 1 | +--------+
Example
Let us look into the following example, where we are using the ISDATE() function with a variable and checking whether the expression is valid or not by running the following query −
DECLARE @expression VARCHAR(23); SET @expression= '2023/02/16'; SELECT ISDATE(@expression) AS Result;
Output
On executing the above query, it will generate the following output as shown below −
+--------+ | Result | +--------+ | 1 | +--------+
Example
Consider the following example, where we are going to print valid date or invalid date, depending on the return value is 1 or 0, by using the following query −
To use the return value, you can use a conditional expression (rather than simply display either 0 or 1).
IF ISDATE('2023-02-16')=1 PRINT 'Valid Date' ELSE PRINT 'Invalid Date';
Output
On running the above query, it will generate an output as shown below −
Valid Date
Example
The return value of the ISDATE() depends upon the type of language and date format settings that are going to chosen by the user.
Letâs consider the simple example where we going to observe how changing the language setting can cause the same value to have several outcomes.
In British language
Execute the following query, where the language was set to the British.
SET LANGUAGE British; SELECT ISDATE('16/02/2023') AS 'in British';
Output
When we execute the above query, the output is obtained as follow −
+------------+ | in British | +------------+ | 1 | +------------+
In us_english language
We are going to use the same value but the difference was the language was set to us_english
SET LANGUAGE us_english; SELECT ISDATE('16/02/2023') AS 'in us_english';
Output
When the above query gets executed, it will generate the following output as shown below −
+---------------+ | in us_english | +---------------+ | 0 | +---------------+
In dmy format
The ISDATE() function depends upon the type of format setting chosen by the user.
Considering the simple example, where we are going to observe how format settings makes the same value to have different return values.
Execute the following query, where we are setting the format setting to dmy.
SET DATEFORMAT dmy; SELECT ISDATE('16/02/2023') AS 'DATEFORMAT is dmy';
Output
Running the above query, generate the following output as shown below −
+-------------------+ | DATEFORMAT is dmy | +-------------------+ | 1 | +-------------------+
In mdy format
Considering the same value and execute the following query by changing the format setting to mdy.
SET DATEFORMAT mdy; SELECT ISDATE('16/02/2023') AS 'DATEFORMAT is mdy';
Output
When we execute the above query, the output is obtained as follows
+-------------------+ | DATEFORMAT is mdy | +-------------------+ | 0 | +-------------------+
To Continue Learning Please Login
Login with Google