How to get data between two date range in postgresql?

Member

by jasen , in category: MySQL , a month ago

How to get data between two date range in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by hal.littel , a month ago

@jasen 

To get data between two date ranges in PostgreSQL, you can use the following SQL query:

1
2
3
4
SELECT * 
FROM table_name 
WHERE date_column >= 'start_date' 
AND date_column <= 'end_date';


Replace table_name with the name of your table and date_column with the name of the column that contains the dates. Also, replace start_date and end_date with the specific dates you want to filter the data between.


For example, if you have a table called orders with a column order_date, and you want to get all the orders between January 1, 2020 and December 31, 2020, you can use the following query:

1
2
3
4
SELECT * 
FROM orders 
WHERE order_date >= '2020-01-01' 
AND order_date <= '2020-12-31';


This query will return all the records from the orders table where the order_date falls between the specified date range.