Question:easy

Write SQL queries to perform the following:

(I) Display the month (in numeric form) of the date '2026-01-01'.

(II) Display only the year part from the date '2026-01-01'.

Show Hint

Use the MySQL date functions MONTH() and YEAR() on the given date.
Updated On: Oct 20, 2026
Show Solution

Solution and Explanation

Step 1: Pick the right built-in function:
A date is stored as year-month-day. SQL gives us functions that pull one piece out of it. We need the month number first and then the year.

Step 2: Use EXTRACT for the month:
EXTRACT(unit FROM date) returns the chosen part of the date.
With the unit MONTH it returns the month as a number.
SELECT EXTRACT(MONTH FROM '2026-01-01');

The result is 1, because January is the first month.

Step 3: Use EXTRACT for the year:
With the unit YEAR the same function returns the year.
SELECT EXTRACT(YEAR FROM '2026-01-01');

The result is 2026.

Step 4: Shorter forms:
The functions MONTH('2026-01-01') and YEAR('2026-01-01') give the same two results and are shorter to type. Both forms are accepted.

Final Answer:
(I) SELECT MONTH('2026-01-01'); returns 1.
(II) SELECT YEAR('2026-01-01'); returns 2026.
Was this answer helpful?
0

Top Questions on Text Date and Math Functions in MySQL