PHP cal_info() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Calendar

Definition

In PHP, cal_info() returns information about a calendar, such as its name, its month names and the maximum number of days in a month.

If you pass a calendar constant like CAL_GREGORIAN, you get one array of details. If you pass nothing (or -1), you get an array that describes all four supported calendars. It is mostly used for lookups, for example to build a list of month names.

Syntax

Call cal_info() with the values you need. Start with this line.

PHP
$info = cal_info(CAL_GREGORIAN);
CallWhat it does
cal_info(CAL_GREGORIAN)Returns the details of the Gregorian calendar.
cal_info()Returns an array that holds the details of all four calendars.
cal_info(CAL_JEWISH)['calname']Returns the text Jewish.

The result for one calendar has the keys months, abbrevmonths, maxdaysinmonth, calname and calsymbol. The months arrays start at index 1, so $info['months'][1] is January.

Library declarations
PHP
cal_info(int $calendar = -1): array

Parameters

ParameterDescription
calendarOptional. The calendar to describe: CAL_GREGORIAN (0), CAL_JULIAN (1), CAL_JEWISH (2) or CAL_FRENCH (3). The default is -1, which returns information about all calendars.

Return Value

Return ValueDescription
arrayFor one calendar: an array with months, abbrevmonths, maxdaysinmonth, calname and calsymbol. For -1: an array of those arrays, indexed by the calendar number.

PHP Examples

Example 1 — Describe the Gregorian Calendar

Ask for the Gregorian calendar and read a few of the values from the returned array.

PHP
<?php
$info = cal_info(CAL_GREGORIAN);

echo $info['calname'], PHP_EOL;
echo $info['calsymbol'], PHP_EOL;
echo $info['maxdaysinmonth'], PHP_EOL;
echo $info['months'][2], ' (', $info['abbrevmonths'][2], ')', PHP_EOL;

How It Works

  1. CAL_GREGORIAN selects the Gregorian calendar.
  2. calname and calsymbol give the readable name and the constant name.
  3. maxdaysinmonth is the longest month in this calendar, which is 31 days.
  4. The months arrays start at 1, so index 2 is February with the short form Feb.

Example 2 — All Calendars and Invalid IDs

Call cal_info() with no argument to see every calendar. A calendar number that does not exist throws an error.

PHP
<?php
foreach (cal_info() as $id => $info) {
    echo $id, ': ', $info['calname'], ' - ', count($info['months']), ' months', PHP_EOL;
}

try {
    cal_info(99);
} catch (ValueError $e) {
    echo 'Invalid calendar ID', PHP_EOL;
}

How It Works

  1. Without an argument, cal_info() returns one entry for each supported calendar.
  2. The array keys are the calendar numbers 0 to 3.
  3. The Jewish and French calendars have 13 months, so count() returns 13 for them.
  4. Calendar 99 does not exist, so PHP 8 throws a ValueError that we catch.

Example 3 — Compare maxdaysinmonth

Loop over the calendar constants and compare the longest month in each calendar.

PHP
<?php
$calendars = [CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH, CAL_FRENCH];

foreach ($calendars as $id) {
    $info = cal_info($id);
    echo $info['calsymbol'], ' => ', $info['maxdaysinmonth'], PHP_EOL;
}

How It Works

  1. We list the four calendar constants in an array.
  2. The loop calls cal_info() once for each calendar.
  3. calsymbol returns the constant name as text, which makes the output easy to read.
  4. The Gregorian and Julian calendars have months up to 31 days, while the other two stop at 30.

Frequently Asked Questions

It returns details about a calendar: the month names, short month names, the maximum days in a month, the calendar name and the constant name.
You get an array that contains the details of all four calendars, with the calendar numbers 0 to 3 as keys.
Months are numbered from 1 in calendars, so PHP uses 1 for the first month. That means $info['months'][1] is January and there is no index 0.
The Gregorian and Julian calendars have 12 months. The Jewish and French calendars are listed with 13 months each.
No. It is part of the calendar extension, which may need to be enabled with extension=calendar in php.ini or installed as the php-calendar package.

Next: cal_to_jd()

cal_to_jd() converts a date in a chosen calendar into a Julian Day number, which is a simp.

cal_to_jd() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful