CodeBlanks Logo Icon CodeBlanks

Summary - Date functions

Compute age and durations with EXTRACT and DATEDIFF.

Summary - Date functions

In this group you learned CURRENT_DATE, EXTRACT, INTERVAL, DATEDIFF and DATE_FORMAT. Date math is now easy.

SELECT EXTRACT(YEAR FROM CURRENT_DATE) AS yil;

This query returns the current year.

The expression EXTRACT(YEAR FROM CURRENT_DATE) AS yil is evaluated and returned.

Practice Summary - Date functions

Select the month of order_date aliased as ay from orders.

Starter code

query.sql
-- summary date
SELECT
FROM orders

Sample solution

query.sql
SELECT EXTRACT(MONTH FROM order_date) AS ay
FROM orders

Expected output

ay
1
2

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which gives the current year?

  • EXTRACT(YEAR FROM CURRENT_DATE) Correct answer
  • YEAR()
  • NOW()
  • DATE()

Explanation: EXTRACT pulls the year from CURRENT_DATE.

2 Summary - Date functions: match the terms

Term Meaning
CURRENT_DATE today
EXTRACT extract
DATEDIFF diff
DATE_FORMAT format

All lessons in Beginner