Find number of days in the month – MySQL

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:
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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s