MySql Date & Time Functions (CBSE Syllabus) board Exam

MySql Date & Time Functions (CBSE Syllabus)


1. Current Date and Time Functions

These functions are used to get the system's current date and time.

FunctionPurposeExampleResult (Assuming Today)
NOW()Returns current date and time.SELECT NOW();2026-01-01 20:05:10
CURDATE()Returns only the current date.SELECT CURDATE();2026-01-01
SYSDATE()Returns current date and time.SELECT SYSDATE();2026-01-01 20:05:10

Note: For the board exam, NOW() and SYSDATE() are often treated as similar, but NOW() returns the time the query started, while SYSDATE() returns the time it executes.


2. Extraction Functions

These functions "pluck" a specific part out of a given date.

FunctionPurposeExampleResult
DATE()Extracts the date part of a date/time.SELECT DATE('2026-12-25 10:30');'2026-12-25'
MONTH()Returns the month number (1–12).SELECT MONTH('2026-12-25');12
MONTHNAME()Returns the full name of the month.SELECT MONTHNAME('2026-12-25');'December'
YEAR()Returns the four-digit year.SELECT YEAR('2026-12-25');2026
DAY() / DAYOFMONTH()Returns the day of the month (1–31).SELECT DAY('2026-12-25');25
DAYNAME()Returns the name of the weekday.SELECT DAYNAME('2026-12-25');'Friday'
DAYOFWEEK()Returns the day index (1=Sun, 2=Mon...).SELECT DAYOFWEEK('2026-12-25');6
DAYOFYEAR()Returns the day of the year (1–366).SELECT DAYOFYEAR('2026-02-01');32

Solved Board-Style Questions

Q1. Write a query to display the name of the current month.

  • Ans: SELECT MONTHNAME(CURDATE());

Q2. Consider a table Library with a column IssueDate. Write a command to display only the year of issue for all books.

  • Ans: SELECT YEAR(IssueDate) FROM Library;

Q3. What is the output of SELECT DAYOFMONTH('2026-08-15');?

  • Ans: 15

Q4. Write the output of:

SELECT MONTHNAME('2026-01-01'), DAYNAME('2026-01-01');

  • Ans: January, Thursday


Important Comparison for Exams

FeatureMONTH()MONTHNAME()
Output TypeNumeric (1, 2, 3...)String (January, February...)
Example5'May'

Common Trap:

When writing dates in a query, always enclose them in single quotes (e.g., '2026-05-20'). If you write YEAR(2026-05-20) without quotes, MySQL treats it as a subtraction $(2026 - 5 - 20)$, leading to a wrong result.

Post a Comment

Please do note create link post in comment section

Previous Post Next Post