The following query will provide the month’s number of days for the specified date. This will come in handy if we need to figure out how many days of the month a given date falls on. If we need to know how many working days are in a month, this will certainly help.
The query uses two functions. One is DAYOFMONTH and LAST_DAY.
LAST_DAY returns the last date for the specified date. DAYOFMONTH returns the date of the current or specified day.
MySQL Query:
SELECT
DAYOFMONTH(LAST_DAY(‘2022-03-14’)) InMarch,
DAYOFMONTH(LAST_DAY(‘2022-02-22’)) InApril,
DAYOFMONTH(LAST_DAY(‘2022-06-14’)) InJune;
It returns 31, 28, and 30 respectively.
Hope this helps.