0% found this document useful (0 votes)
6 views21 pages

MySQL Part 9 - Date & Group Functions

The document provides an overview of date functions in MySQL, including CURDATE(), NOW(), SYSDATE(), DATE(), DAY(), MONTH(), YEAR(), DAYNAME(), and MONTHNAME(), along with their usage examples. It also covers aggregate functions such as SUM(), AVG(), MAX(), MIN(), and COUNT(), detailing how to apply these functions to retrieve data from the employee table. The default date format in MySQL is YYYY-MM-DD, and the document illustrates how to manipulate and extract specific date components.

Uploaded by

tecnklogia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views21 pages

MySQL Part 9 - Date & Group Functions

The document provides an overview of date functions in MySQL, including CURDATE(), NOW(), SYSDATE(), DATE(), DAY(), MONTH(), YEAR(), DAYNAME(), and MONTHNAME(), along with their usage examples. It also covers aggregate functions such as SUM(), AVG(), MAX(), MIN(), and COUNT(), detailing how to apply these functions to retrieve data from the employee table. The default date format in MySQL is YYYY-MM-DD, and the document illustrates how to manipulate and extract specific date components.

Uploaded by

tecnklogia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

MySQL Part - 9

Date Functions
• Date and Time functions allow us to perform many
types of tasks on Date type data.
• The default date format in MySQL is YYYY-MM-DD.
CURDATE()

• Returns the current date in 'YYYY-MM-DD' format

SELECT CURDATE();
2025-04-21
NOW ()

• Returns the current date and time in 'YYYY-MM-DD


HH:MM:SS'

SELECT NOW();
2025-04-21 09:38:00
SYSDATE()
• Returns the current date and time in 'YYYY-MM-DD
HH:MM:SS' format.

SELECT SYSDATE();
2025-04-21 09:38:52
DATE ()
• Extracts the date part of a date/datetime expression

SELECT DATE(NOW( ));


2025-04-21

SELECT DATE('2020-05-07 01:02:03');


2020-05-07

SELECT DATE('2009-10-16 01:02:03');


2009-10-16
DAY ()
• Returns the numeric day from the date passed, in
the range 1 to 31
SELECT DAY(' 2025-04-21');
21

Select id, date_join, day(date_join) from employee;


MONTH ()
• Returns the numeric month from the date passed, in
the range 0 to 12.

SELECT MONTH(NOW());
4

Select id, date_join, month(date_join) from employee;


YEAR ()
• Returns the year for date passed in the range 0 to
9999. Returns values like 1998, 2010, 1996, etc.

SELECT YEAR(NOW());
2020

SELECT id,date_join,year(date_join) from Employee;


DAYNAME ()
• It returns the name of the weekday for the date passed,
like Monday or Friday.

SELECT DAYNAME(' 2025-04-21');


Monday

Select id, date_join, dayname(date_join) from employee;


MONTHNAME ()
• It returns the name of the month for the date passed,
like January or September.

SELECT MONTHNAME(' 2025-04-21');


April

Select id, date_join, monthname(date_join) from employee;


Aggregate/ Group/ Multiple Row
Functions
SUM ()
• Returns the SUM of the values for the given column.

SELECT SUM(salary) FROM employee;

SELECT SUM(salary) FROM employee WHERE city = 'Delhi';


AVG ()
• Returns the AVERAGE of the values of the given column.

SELECT AVG(salary) FROM employee;

SELECT AVG(salary) FROM employee WHERE first_name like '%a';


MAX ()
• Returns the MAXIMUM (highest) of the values for the
given column.

SELECT MAX(salary) FROM employee;

SELECT MAX(salary) FROM employee WHERE city = 'Delhi';


SELECT MAX(first_name) FROM employee;

SELECT MAX(date_join) FROM employee;


MIN ()
• Returns the MINIMUM (lowest) of the values under the
specified column.

SELECT MIN(salary) FROM employee;

SELECT MIN(salary) FROM employee WHERE city = 'Delhi';


SELECT MIN(first_name) FROM employee;

SELECT MIN(date_join) FROM employee;


COUNT ()
• Returns the COUNT of the number of values under the
specified column.

SELECT COUNT(salary) FROM employee;

SELECT COUNT(distinct city) FROM employee;


SELECT COUNT(first_name) FROM employee;

SELECT COUNT(date_join) FROM employee;


Using COUNT (*)
• Using * with count, counts the number of records in
the table.

SELECT COUNT(*) FROM employee;

SELECT COUNT(*) FROM employee where last_name='sharma';

You might also like