image blog sql database

How to Get the Number of Days in a Month in MySQL

By using MySQL we can easily return any data related to days of the month. In the following tutorial we will see how we can follow this step by step methods to get the number of days in a month while sorting MySQL databases.

We need to pass “LAST_DAY()” function in “DAYOFMONTH()” function.


Here is a real-time example of how to get days of month in whole year.

    DAYOFMONTH(LAST_DAY('2030-01-15')) AS "Jan",
    DAYOFMONTH(LAST_DAY('2030-02-15')) AS "Feb",
    DAYOFMONTH(LAST_DAY('2030-03-15')) AS "Mar",
    DAYOFMONTH(LAST_DAY('2030-04-15')) AS "Apr",
    DAYOFMONTH(LAST_DAY('2030-05-15')) AS "May",
    DAYOFMONTH(LAST_DAY('2030-06-15')) AS "Jun",
    DAYOFMONTH(LAST_DAY('2030-07-15')) AS "Jul",
    DAYOFMONTH(LAST_DAY('2030-08-15')) AS "Aug",
    DAYOFMONTH(LAST_DAY('2030-09-15')) AS "Sep",
    DAYOFMONTH(LAST_DAY('2030-10-15')) AS "Oct",
    DAYOFMONTH(LAST_DAY('2030-11-15')) AS "Nov",
    DAYOFMONTH(LAST_DAY('2030-12-15')) AS "Dec";

I hope this makes sense to you. If you have any question, please write to us in comments section.