Question:

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
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Understand the two tasks:
Both tasks use the date '2026-01-01'. Part (I) needs the month as a number. Part (II) needs only the year. MySQL has date functions that cut out one part of a date.

Step 2: Month in numeric form:
The function MONTH(date) returns the month as a number from 1 to 12.
For '2026-01-01' the month part is 01, so MONTH returns 1.
The query is:
SELECT MONTH('2026-01-01');

It displays 1.

Step 3: Year part only:
The function YEAR(date) returns the four-digit year of a date.
For '2026-01-01' it returns 2026.
The query is:
SELECT YEAR('2026-01-01');

It displays 2026.

Step 4: Why not MONTHNAME:
MONTHNAME('2026-01-01') returns the word January, not a number, so it does not answer part (I).

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

Top CBSE CLASS XII Text Date and Math Functions in MySQL Questions

View More Questions