The DAYOFMONTH() function in MySQL is used to return the day of the month (from 1 to 31) for a given date.
Syntax:
DAYOFMONTH(date)
Parameters:
- date: A valid date or datetime expression. If the input is not a valid date, the function returns
NULL.
Example 1: Basic Usage
SELECT DAYOFMONTH('2024-12-23') AS DayOfMonth;
Output:
23
Example 2: Using Current Date
SELECT DAYOFMONTH(CURDATE()) AS TodayDayOfMonth;
Example 3: Invalid Date
SELECT DAYOFMONTH('2024-02-30') AS DayOfMonth;
Output:
NULL
Notes:
- The
DAYOFMONTH()function is equivalent toDAY(). - It is commonly used in queries where day-level extraction is required for filtering, grouping, or calculations.
Related Functions:
DAY(): Returns the day of the month (same asDAYOFMONTH).DAYOFWEEK(): Returns the weekday index (1 for Sunday, 7 for Saturday).DAYOFYEAR(): Returns the day of the year (1 to 366).
No comments:
Post a Comment