MySQL DAY() function
In this context, we will learn how we can use the MySQL DAY() function with proper syntax and good examples.
Introduction of MySQL DAY() function
This function in MySQL is used to return the day of the month for a specified date (a number from 1 to 31). This function equals the DAYOFMONTH() function.
Syntax of the MySQL DAY() function
The syntax of the MySQL DAY() function is given as follows:
DAY(dt)
Parameters or arguments used in MySQL DAY() function:
There is only one parameter is accepted by the DAY() function in MySQL, which is given as follows:
DT: it is the mentioned date to extract the day from it.
Returns:
It will return the day of the month for a specified date (a number from 1 to 31).
Application used for DAY() function:
The DAY() function can be used in the given below MySQL versions.:
- MySQL 5.7
- MySQL 5.6
- MySQL 5.5
- MySQL 5.1
- MySQL 5.0
- MySQL 4.1
- MySQL 4.0
- MySQL 3.23
Examples of MySQL DAY() function:
Now we will look into some MySQL DAY() function examples and will explore how we can use the DAY function in MySQL.
Example-1 :
Now in this example, we will get the day of the month from a specified date, “2020-11-21,” in MySQL.
SELECT DAY("2020-11-21");
Output:
21
1 row in set (0.00 sec)
Example-2 :
In this example, we will get the day of the month from a specified date, “2020-11-17 07:12:23,” in MySQL.
SELECT DAY("2020-11-17 07:12:23");
Output:
17
1 row in set (0.00 sec)
Example-3 :
In this example, we will get the day of the month for the current system date in MySQL.
SELECT DAY(CURDATE());
Output:
16
1 row in set (0.00 sec)
Application of MySQL DAY() function:
This function is used to return the day of the month for a specified date (a number from 1 to 31).
Summary:
In the above context, we have learned how we can use the DAY() function in MySQL used to return the day of the month for a specified date (a number from 1 to 31).