Menu
Coddy logo textTech

Handling Dates Part 1

Part of the Fundamentals section of Coddy's SQL journey — lesson 31 of 72.

Dates in SQL have a specific format and we can query them similarly to numbers. To write a date in a query we will use the format: YYYY-MM-DD (2012-09-24)

To query dates we can use all the operators we already know - bigger, smaller, or equal within the WHERE keyword:

SELECT * FROM table1
WHERE col1 > '2011-01-13'

We can even use the BETWEEN keyword:

SELECT * FROM table1
WHERE col1 BETWEEN '2010-01-01' AND '2010-02-25'
challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>games</strong>: <strong>id</strong>, <strong>date</strong>

Fetch all of the game ids that are not played in the winter.
Winter dates are: 2022-12-21 - 2023-03-20. Only these days should not be included.

Sort them by the date in descending order and rename the column to game

Cheat sheet

Dates in SQL use the format YYYY-MM-DD (e.g., 2012-09-24).

Query dates using comparison operators:

SELECT * FROM table1
WHERE col1 > '2011-01-13'

Use BETWEEN for date ranges:

SELECT * FROM table1
WHERE col1 BETWEEN '2010-01-01' AND '2010-02-25'

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals