Informatics Practices

SQL Date Functions | NOW(), DATE(), MONTH(), MONTHNAME(), YEAR(), DAY(), DAYNAME() | Complete Notes | CBSE Class 12 Informatics Practices (2026–27)

Class 12 · Informatics Practices

SQL Date Functions

Date functions are used to retrieve and manipulate date and time values stored in a database. They help generate reports, filter records based on dates, and extract specific parts such as the year, month, or day from a date.

According to the CBSE Class 12 Informatics Practices syllabus, the following SQL date functions are included:

  • NOW()
  • DATE()
  • MONTH()
  • MONTHNAME()
  • YEAR()
  • DAY()
  • DAYNAME()

Sample Table

EmpID Name JoiningDate
101 Amit 2023-05-12
102 Neha 2022-11-20
103 Rohan 2024-01-08

1. NOW()

Definition

The NOW() function returns the current system date and time.

Syntax

NOW()

Example

SELECT NOW();
Sample Output
2026-07-24 10:30:45

Note: The output depends on the current system date and time.


2. DATE()

Definition

The DATE() function extracts only the date part from a date and time value.

Syntax

DATE(date_expression)

Example

SELECT DATE(NOW());
Sample Output
2026-07-24

3. MONTH()

Definition

The MONTH() function returns the month number (1–12) from a given date.

Syntax

MONTH(date)

Example

SELECT MONTH('2026-07-24');
Output
7

Using MONTH() with a Table

SELECT Name,
       MONTH(JoiningDate)
FROM Employee;

4. MONTHNAME()

Definition

The MONTHNAME() function returns the name of the month.

Syntax

MONTHNAME(date)

Example

SELECT MONTHNAME('2026-07-24');
Output
July

5. YEAR()

Definition

The YEAR() function extracts the year from a date.

Syntax

YEAR(date)

Example

SELECT YEAR('2026-07-24');
Output
2026

6. DAY()

Definition

The DAY() function returns the day of the month from a date.

Syntax

DAY(date)

Example

SELECT DAY('2026-07-24');
Output
24

7. DAYNAME()

Definition

The DAYNAME() function returns the name of the day of the week.

Syntax

DAYNAME(date)

Example

SELECT DAYNAME('2026-07-24');
Output
Friday

Using Date Functions with a Table

Display Joining Year

SELECT Name,
       YEAR(JoiningDate)
FROM Employee;

Display Joining Month Name

SELECT Name,
       MONTHNAME(JoiningDate)
FROM Employee;

Display Joining Day

SELECT Name,
       DAY(JoiningDate)
FROM Employee;

Display Day Name

SELECT Name,
       DAYNAME(JoiningDate)
FROM Employee;

Comparison of Date Functions

Function Purpose Example
NOW() Current date and time NOW()
DATE() Extract date DATE(NOW())
MONTH() Month number MONTH('2026-07-24')
MONTHNAME() Month name MONTHNAME('2026-07-24')
YEAR() Year YEAR('2026-07-24')
DAY() Day of month DAY('2026-07-24')
DAYNAME() Weekday name DAYNAME('2026-07-24')

Real-Life Applications

Function Application
NOW() Display current login time.
DATE() Store only the date portion.
MONTH() Generate monthly reports.
MONTHNAME() Display readable month names.
YEAR() Filter yearly records.
DAY() Track daily transactions.
DAYNAME() Find weekday-wise reports.

Common Errors

Error Reason
Incorrect Date Format Date not written in YYYY-MM-DD format.
Unknown Column Incorrect column name.
Syntax Error Missing brackets or quotes.

Quick Revision

Function Returns
NOW() Current date & time
DATE() Date only
MONTH() Month number
MONTHNAME() Month name
YEAR() Year
DAY() Day of month
DAYNAME() Weekday name

CBSE Exam Tips

  • NOW() returns both the current date and time.
  • DATE() extracts only the date portion.
  • MONTH() returns a numeric month (1–12).
  • MONTHNAME() returns the full month name.
  • DAY() returns the day of the month, while DAYNAME() returns the weekday name.
  • Always write date literals in the YYYY-MM-DD format.

Summary

SQL Date Functions help retrieve and manipulate date and time values stored in databases. Functions such as NOW(), DATE(), MONTH(), MONTHNAME(), YEAR(), DAY(), and DAYNAME() are widely used in reporting, filtering, and analyzing date-based information. These functions are important for both the CBSE Class 12 Informatics Practices theory and practical examinations.