How to Get a Date Greater Than Today in PostgreSQL?

PostgreSQL supports numerous built-in functions that assist us in manipulating the date and time values efficiently. In Postgres, the built-in functions like NOW(), CURRENT_DATE, CURRENT_TIMESTAMP, and LOCALTIMESTAMP are used with the SELECT statement to get today’s date. These functions can be used with comparison operators to filter the data based on today’s date.

This article explains how to get dates greater than today from a Postgres table.

How to Get a Date Greater Than Today in Postgre?

The comparison operators like greater than “>” and greater than or equal to “>=” can be used with the “CURRENT_DATE” function to get a date greater than today. Use the following syntax to get the table’s data greater than or equal to the current date (today):

SELECT col_list
FROM tab_name
WHERE col_name > CURRENT_DATE;

In the above syntax:

- The “SELECT” statement will retrieve the specified columns of the selected table.
- The tab_name is the name of the given table.
- The “WHERE” clause will filter the table’s record based on the current date.

All in all, the above query will return the records greater than today from the given table.

Sample Table

A sample table named bikes_info has already been created in the database whose data is enlisted in the following snippet:

SELECT * FROM bikes_info;
img

The result set demonstrates that the “launching_date” column contains some dates greater than today.

Example 1: Getting Dates Greater Than Today

Suppose we want to get the data of all those bikes that are not launched yet. To fulfill this task, we will use the CURRENT_DATE function with the greater than operator, as follows:

SELECT * 
FROM bikes_info
WHERE launching_date > CURRENT_DATE;

The above query will retrieve the details of only those bikes whose launching date is greater than today:

img

The bikes that have not yet been launched are displayed along with their model, price, and launch date.

Example 2: Getting Dates Greater Than or Equal to Today

In the above example, replacing the ">" sign with ">=" retrieves the dates greater than or equal to today:

SELECT * 
FROM bikes_info
WHERE launching_date >= CURRENT_DATE;
img

This time the result set displays the bikes whose launch date is today or greater than today.

Example 3: Getting Dates Greater Than Today Using NOW() Function

In Postgres, built-in functions like NOW(), CURRENT_TIMESTAMP, and LOCALTIMESTAMP can also be used with the “>” or “>=” operator to get a date greater than today:

SELECT * 
FROM bikes_info
WHERE launching_date >= NOW();
img

The output shows the launching dates greater than or equal to today in PostgreSQL.

Note: The comparison operators like “<”, and “<=” can be used with the CURRENT_TIMESTAMP, NOW(), CURRENT_DATE, and LOCALTIMESTAMP, functions to get the date less than or equal to today.

Conclusion

In PostgreSQL, comparison operators like greater than “>” and greater than or equal to “>=” can be used with the “CURRENT_DATE” function to get a date greater than or equal to today. Some other built-in date functions like NOW(), CURRENT_TIMESTAMP, and LOCALTIMESTAMP can also be used with the “>” or “>=” operator to get a date greater than today. This write-up presented a detailed guide on how to get a date greater than or equal to today in Postgres.