---
title: "How to check a valid date in SQL Server?"  
description: "How to check a valid date in SQL Server?"  
author: "Ashutosh Kumar Verma"  
published: 2021-11-24  
updated: 2023-06-20  
canonical: https://www.mindstick.com/interview/33849/how-to-check-a-valid-date-in-sql-server  
category: "mssql server"  
tags: ["sql server", "sql"]  
reading_time: 3 minutes  

---

# How to check a valid date in SQL Server?

## ISDATE():

SQL ISDATE() is used to check the valid date. If given date is valid then it returns 1 otherwise returns 0.

Example:

```
SELECT ISDATE('2021/11/25');
```

```
Output     1
```

## Answers

### Answer by Aryan Kumar

Sure, I can help you with that.

To check a valid date in SQL Server, you can use the `ISDATE()` function. The `ISDATE()` function takes a date expression as input and returns 1 if the expression is a valid date, and 0 if the expression is not a valid date.

For example, the following query will check if the value '2023-01-01' is a valid date:

SQL

```plaintext
SELECT ISDATE('2023-01-01');
```

This query will return the value 1, which means that the value '2023-01-01' is a valid date.

Here is the syntax for the `ISDATE()` function:

SQL

```plaintext
ISDATE ( expression )
```

- `expression` is the date expression that you want to check.

The `ISDATE()` function can also be used to check for a valid time or datetime. For example, the following query will check if the value '2023-01-01 12:00:00' is a valid datetime:

SQL

```plaintext
SELECT ISDATE('2023-01-01 12:00:00');
```

This query will also return the value 1, which means that the value '2023-01-01 12:00:00' is a valid datetime.

### Answer by Rocky Dada

In SQL Server, you can use the **ISDATE** function to check if a given string is a valid date. The **ISDATE** function returns 1 if the input string can be converted to a date, and 0 otherwise.

Here's an example query that uses the **ISDATE** function to check if a string is a valid date:

arduinoCopy code

`SELECT ISDATE('2022-04-11') AS IsDateValid;`

In this example, the **ISDATE** function is used to check if the string '2022-04-11' is a valid date. The result of the query will be a single column called **IsDateValid**, which will contain the value 1 if the string is a valid date, and 0 if it is not.

You can also use the **TRY_CONVERT** function to convert a string to a date, and check if the conversion was successful using the **IS NOT NULL** operator. Here's an example query that demonstrates this approach:

sqlCopy code

`SELECT TRY_CONVERT(date, '2022-04-11') AS DateValue WHERE TRY_CONVERT(date, '2022-04-11') IS NOT NULL;`

In this example, the **TRY_CONVERT** function is used to convert the string '2022-04-11' to a date. The **WHERE** clause checks if the conversion was successful, by verifying that the result of the **TRY_CONVERT** function is not null. The result of the query will be a single column called **DateValue**, which will contain the date value if the conversion was successful. If the conversion was not successful, the query will not return any rows.

### Answer by Ashutosh Kumar Verma

## ISDATE():

SQL ISDATE() is used to check the valid date. If given date is valid then it returns 1 otherwise returns 0.

Example:

```
SELECT ISDATE('2021/11/25');
```

```
Output     1
```


---

Original Source: https://www.mindstick.com/interview/33849/how-to-check-a-valid-date-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
