Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Calendar Functionscal_from_jd>
^Calendar FunctionsLast updated: Mon, 26 Oct 2026

cal_days_in_month

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

cal_days_in_month — Return the number of days in a month for a given year and calendar

Description

function cal_days_in_month(int $calendar, int $month, int $year): int

This function will return the number of days in the month of year for the specified calendar.

Parameters

calendar

Calendar to use for calculation

month

Month in the selected calendar

year

Year in the selected calendar

Return Values

The length in days of the selected month in the given calendar

Errors/Exceptions

Throws a ValueError if calendar is not a valid calendar ID, if month or year is outside the supported range, or if the date is not valid in the given calendar.

Changelog

Version Description
8.0.0 Now throws a ValueError if calendar is not a valid calendar ID or the date is not valid. Previously, an E_WARNING was raised and false was returned.

Examples

Example #1 cal_days_in_month() example

<?php
$number = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31
echo "There were {$number} days in August 2003";
?>


<Calendar Functionscal_from_jd>
^Calendar FunctionsLast updated: Mon, 26 Oct 2026