Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dealing with dates
Working with time data
Date and time date
19. Using BETWEEN with date and time data
Extracting dates and times
Doing arithmetic with dates
Converting date and time data
Building date and time data from parts
Summary and review

Instruction

Nice job! As you might expect, you can use BETWEEN with date and time data:

SELECT
  Id
FROM Aircraft
WHERE LaunchedDatetime
BETWEEN '2015-11-01'
  AND '2015-12-01';

As you know from previous exercises, the zeros are added automatically. This is very convenient, but you need to watch out when retrieving rows for an entire month, year, etc. If you want all aircraft launched in November 2015, you must use the condition just as we've shown it to you: BETWEEN '2015-11-01' AND '2015-12-01'.

The second date is 1 December because the database will add the missing zeroes: '2015-12-01 00:00:00'. This is the exact point in time when December starts. If you wrote the second date as the last day of November (2015-11-30), you would skip all the aircraft that were launched on November 30, 2015. Keep that in mind.

Exercise

Find all aircraft launched in 2015. Show the Id and LaunchedDatetime columns.

Stuck? Here's a hint!

Remember about the proper date format and use quotes: 'YYYY-MM-DD'. Use BETWEEN. The second date should be January 1, 2016.