Skip to content

php_ref_calendar

The PHP Calendar extension provides a set of functions for converting between different calendar systems (Gregorian, Julian, Jewish, French Republican) using the Julian Day Count as an intermediary.

The Julian Day Count is a continuous count of days since noon Universal Time on January 1, 4713 BC (on the Julian calendar).

Note: While available, these functions are relatively low-level. For most modern date and time manipulations in PHP, the built-in DateTime class, DateInterval, DateTimeZone, and the IntlDateFormatter class (from the Intl extension) offer a more powerful, flexible, and object-oriented approach.

Conversion Process: To convert from Calendar A to Calendar B using this extension, you typically convert the date from Calendar A to its Julian Day Count, and then convert that Julian Day Count to the date in Calendar B.

Clarification: The Julian Day Count is distinct from the Julian Calendar system itself.

To use these functions, PHP needs to be compiled with calendar support. You can enable it during compilation using the --enable-calendar flag.

On many systems (including pre-compiled Windows distributions and common Linux package manager installs), the calendar extension is often included and enabled by default. You can verify if it’s enabled by checking your phpinfo() output.

FunctionDescription
cal_days_in_month()Returns the number of days in a month for a specified year and calendar system.
cal_from_jd()Converts a Julian Day Count into a date representation for a specified calendar system.
cal_info()Returns information about a specified calendar system (e.g., months, days).
cal_to_jd()Converts a date from a specified calendar system into its Julian Day Count.
easter_date()Returns the Unix timestamp for midnight on Easter Sunday for a specified year (uses Gregorian calendar rules after 1752 by default).
easter_days()Returns the number of days after March 21st on which Easter Sunday falls for a specified year.
frenchtojd()Converts a date from the French Republican calendar to its Julian Day Count.
gregoriantojd()Converts a date from the Gregorian calendar to its Julian Day Count.
jddayofweek()Returns the day of the week (e.g., ‘Monday’, 1) for a given Julian Day Count.
jdmonthname()Returns the month name (e.g., ‘January’, ‘Jan’) for a given Julian Day Count and calendar system.
jdtofrench()Converts a Julian Day Count to a date in the French Republican calendar.
jdtogregorian()Converts a Julian Day Count to a date in the Gregorian calendar (YYYY-MM-DD format).
jdtojewish()Converts a Julian Day Count to a date in the Jewish calendar.
jdtojulian()Converts a Julian Day Count to a date in the Julian calendar.
jdtounix()Converts a Julian Day Count to a Unix timestamp (seconds since the Unix Epoch).
jewishtojd()Converts a date from the Jewish calendar to its Julian Day Count.
juliantojd()Converts a date from the Julian calendar to its Julian Day Count.
unixtojd()Converts a Unix timestamp to its corresponding Julian Day Count.

These constants are used as parameters for the calendar functions, typically specifying the calendar system or formatting options.

Constant Type Description
----------------------------- ------- ----------------------------------------------------
CAL_GREGORIAN Integer Gregorian Calendar
CAL_JULIAN Integer Julian Calendar
CAL_JEWISH Integer Jewish Calendar
CAL_FRENCH Integer French Republican Calendar
CAL_NUM_CALS Integer Total number of available calendars
CAL_DOW_DAYNO Integer Day of the week as number (0=Sunday, 1=Monday,...)
CAL_DOW_SHORT Integer Abbreviated day name (e.g., "Mon")
CAL_DOW_LONG Integer Full day name (e.g., "Monday")
CAL_MONTH_GREGORIAN_SHORT Integer Abbreviated Gregorian month name (e.g., "Jan")
CAL_MONTH_GREGORIAN_LONG Integer Full Gregorian month name (e.g., "January")
CAL_MONTH_JULIAN_SHORT Integer Abbreviated Julian month name
CAL_MONTH_JULIAN_LONG Integer Full Julian month name
CAL_MONTH_JEWISH Integer Jewish month name
CAL_MONTH_FRENCH Integer French Republican month name
CAL_EASTER_DEFAULT Integer Calculate Easter per Gregorian rules post-1752
CAL_EASTER_ROMAN Integer Calculate Easter per Gregorian rules post-1582
CAL_EASTER_ALWAYS_GREGORIAN Integer Calculate Easter using proleptic Gregorian rules
CAL_EASTER_ALWAYS_JULIAN Integer Calculate Easter using Julian rules
CAL_JEWISH_ADD_ALAFIM_GERESH Integer Add geresh symbol (like ') before the thousands digit (Jewish Year)
CAL_JEWISH_ADD_ALAFIM Integer Add the word 'alafim' for thousands digit (Jewish Year)
CAL_JEWISH_ADD_GERESHAYIM Integer Add gershayim symbol (like ") before last letter of year (Jewish Year)