How to calculate days in a month using PHP

If you want to calculate number of days in specific month year then In php there is pre-define function called cal_days_in_month which return the number of days in a month for a given year and calendar.

Copy Paste below function in your PHP file and use it to calculate days in a month.

function getDays($month, $year) {
 return $d." Days";

This simple one line PHP function provides the number of days in a month, taking into account leap years as well.

See Live Demo.


Posted in: PHP

One Reply to “How to calculate days in a month using PHP”

  1. i want calculate no of days in a selected month using type=month or type=date() the result will be echo in next “text” field please help me.
    function getDays($month) {


    <input type="text" id="days" class="form-control" name="days" value="”>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.