GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.tutorialspoint.com — SQL - ISDATE() Function
Selected Reading
SQL - ISDATE() FunctionThe 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. SyntaxFollowing is the syntax for the SQL ISDATE() function − ISDATE(expression) ParametersThis function accepts only one parameter as discussed below −
Note − If the given date contains only a time part the month() function returns 1. ExampleIn the following query, we are checking whether the expression is valid or not − SELECT ISDATE('2023-02-16');
OutputWhen we execute the above query, the output is obtained as follows − +---------+ | no name | +---------+ | 1 | +---------+ ExampleHere, we are trying to find the given expression is valid or not using the following query − SELECT ISDATE('Tutorialspoint');
OutputOn executing the above query, the output is displayed as follows − +---------+ | no name | +---------+ | 0 | +---------+ ExampleThe 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; OutputThe output for the above query is produced as given below − +--------+ | Result | +--------+ | 0 | +--------+ ExampleLook 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;
OutputIf we execute the above query, the result is produced as follows − +--------+ | Result | +--------+ | 1 | +--------+ ExampleConsidering 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;
OutputOn executing the above query, it will generate the following output as shown below − +--------+ | Result | +--------+ | 1 | +--------+ ExampleLet 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; OutputOn executing the above query, it will generate the following output as shown below − +--------+ | Result | +--------+ | 1 | +--------+ ExampleConsider 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';
OutputOn running the above query, it will generate an output as shown below − Valid Date ExampleThe 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 languageExecute the following query, where the language was set to the British. SET LANGUAGE British;
SELECT ISDATE('16/02/2023') AS 'in British';
OutputWhen we execute the above query, the output is obtained as follow − +------------+ | in British | +------------+ | 1 | +------------+ In us_english languageWe 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';
OutputWhen the above query gets executed, it will generate the following output as shown below − +---------------+ | in us_english | +---------------+ | 0 | +---------------+ In dmy formatThe 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';
OutputRunning the above query, generate the following output as shown below − +-------------------+ | DATEFORMAT is dmy | +-------------------+ | 1 | +-------------------+ In mdy formatConsidering 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';
OutputWhen we execute the above query, the output is obtained as follows +-------------------+ | DATEFORMAT is mdy | +-------------------+ | 0 | +-------------------+ sql-date-functions.htm
Advertisements
|
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |