Best April deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dealing with dates
8. Using BETWEEN with dates
Working with time
Date and time data types in PostgreSQL
Extracting dates and times
Timezone conversion
Format date and time
Current date and time data
Summary

Instruction

You can also use the BETWEEN operator to return certain dates. In this way, you can select a range of dates. The following query selects information based on production dates for the year 2010:

SELECT
  id,
  model,
  produced_date
FROM aircraft
WHERE produced_date BETWEEN '2010-01-01'
  AND '2010-12-31';

This will find all the aircraft produced between January 1, 2010 and December 31, 2010, including the starting and ending dates.

Exercise

Select the id and flight_date of all flights which did not take place in 2015.

Stuck? Here's a hint!

Negate the BETWEEN with NOT:

NOT BETWEEN '2015-01-01' AND '2015-12-31'