SQL Query to Check Given Format of a Date - GeeksforGeeks (2024)

Improve

Here, we are going to see how to find the SQL Query to check whether the date passed to query is the date of the given format or not. In this article, we will be making use of the Microsoft SQL Server as our database.

Here, we will first create a database named “geeks” then we will create a table “department” in that database. After, that we will execute our query on that table.

Creating Database:

CREATE DATABASE geeks;

Using the Database:

USE geeks;

Table Definition:

We have the following table named as department in our geeks database.

CREATE TABLE department( ID int, SALARY int, NAME Varchar(20), JoinDate datetime );

Adding value into the table:

INSERT INTO department VALUES (1, 34000, 'Neha', '09-24-2013')INSERT INTO department VALUES (2, 33000, 'Hema', '02-02-2015')INSERT INTO department VALUES (3, 36000, 'Jaya', '09-09-2017')INSERT INTO department VALUES (4, 35000, 'Priya', '05-18-2018')INSERT INTO department VALUES (5, 34000, 'Ketan', '02-25-2019')

To verify the contents of the table use the following SQL query:

SELECT * FROM department;

SQL Query to Check Given Format of a Date - GeeksforGeeks (1)

Checking whether the date passed to query is the date of the given format or not:

SQL has IsDate() function which is used to check the passed value is date or not of specified format, it returns 1(true) when the specified value is date otherwise it return 0(false).

Syntax:

SELECT ISDATE(‘Date’) AS “Format”;

OR

SELECT *, ISDATE(‘ColumnName’) AS “Format” FROM TABLENAME ;

Example:

SELECT TOP 1000 [ID] ,[SALARY] ,[NAME] ,[JoinDate], ISDATE(JoinDate) as Format FROM [department]

SQL Query to Check Given Format of a Date - GeeksforGeeks (2)


Last Updated : 11 Aug, 2021

Like Article

Save Article

Share your thoughts in the comments

Please Login to comment...

SQL Query to Check Given Format of a Date - GeeksforGeeks (2024)
Top Articles
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6297

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.