Summary - Date functions
- SQL course
- Beginner
- Lesson 58/115
- 5 min
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
-- summary date
SELECT
FROM ordersSample solution
SELECT EXTRACT(MONTH FROM order_date) AS ay
FROM ordersExpected 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 |