Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dealing with dates
6. The DATE data type
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

Good. As you saw, dates are shown in the following format, which is the recommended PostgreSQL format:

YYYY-MM-DD

First we have the year, then the month, and finally the day.

In PostgreSQL, the date data type is the default way to store date information. This data type has a range of '4713-01-01 BC' to '5874897-12-31 AD'. If we want to use dates in our queries, we need to enclose them with single quotes, like this:

SELECT
  id,
  model
FROM aircraft
WHERE produced_date = '2014-04-05';

This query will return the id and model for all aircraft produced on April 5, 2014.

Exercise

Select the following columns: id, route_code, delay and flight_date for flights made on January 1, 2016 or April 3, 2016.

Stuck? Here's a hint!

You will need two conditions, joined with OR. Remember the proper date format, and don't forget the single quotes:

'YYYY-MM-DD'