Skip to content
Related Articles

Related Articles

Improve Article

SQL Query to Check if Date is Greater Than Today in SQL

  • Last Updated : 15 Oct, 2021
Geek Week

In this article, we will see the SQL query to check if DATE is greater than today’s date by comparing date with today’s date using the GETDATE() function. This function in SQL Server is used to return the present date and time of the database system in a ‘YYYY-MM-DD hh:mm: ss. mmm’ pattern.

Features:

  • This function is used to find the present date and time of the database system.
  • This function comes under Date Functions.
  • This function doesn’t accept any parameter.
  • This function returns output in ‘YYYY-MM-DD hh:mm: ss. mmm‘ format.

To check a current date we use simply GETDATE( ) function.

Query:

SELECT GETDATE();        

Output:



Now, take an example to check if the date is greater than today’s date in MS SQL Server. For this we follow given below steps:

Step 1: Create a database

we can use the following command to create a database called geeks.

Query:

CREATE DATABASE geeks;

Step 2: Use database

Use the below SQL statement to switch the database context to geeks:

Query:



USE geeks;

Step 3: Table definition

We have the following geeks for geeks in our geek’s database.

Query:

CREATE TABLE geeksforgeeks(
NAME VARCHAR(20),
Ordered DATE,
Deliver DATE);

Step 4: Insert data into a table

Query:

INSERT  INTO geeksforgeeks VALUES
 ('ROMY', '2021-01-16', '2021-03-12'),
('AVINAV', '2021-11-12', '2021-12-12'),
 ('PUSHKAR', '2021-06-23', '2021-10-13');

Step 5: For a view a table data

To see the content of the table, run the below command

Query:

SELECT * FROM geeksforgeeks;

Output:



Step 6:  Check date greater than today date or not

  • For this, we will check from the table, which row has delivered a value greater than today’s date.

Query:

SELECT * FROM geeksforgeeks WHERE Deliver > GETDATE();

Output:

Returned value whose date is 2021-12-12 and 2021-10-13 which is greater than 2021-09-22 (Today’s date)

  • Check whose ordered date is greater than today’s date.

Query:

SELECT * FROM geeksforgeeks WHERE Ordered > GETDATE();

Output:

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

My Personal Notes arrow_drop_up
Recommended Articles
Page :