php_ref_calendar
PHP Calendar Functions
Section titled “PHP Calendar Functions”PHP Calendar Introduction
Section titled “PHP Calendar Introduction”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.
Installation
Section titled “Installation”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.
PHP Calendar Functions
Section titled “PHP Calendar Functions”| Function | Description |
|---|---|
| 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. |
PHP Predefined Calendar Constants
Section titled “PHP Predefined Calendar Constants”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 CalendarCAL_JULIAN Integer Julian CalendarCAL_JEWISH Integer Jewish CalendarCAL_FRENCH Integer French Republican CalendarCAL_NUM_CALS Integer Total number of available calendarsCAL_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 nameCAL_MONTH_JULIAN_LONG Integer Full Julian month nameCAL_MONTH_JEWISH Integer Jewish month nameCAL_MONTH_FRENCH Integer French Republican month nameCAL_EASTER_DEFAULT Integer Calculate Easter per Gregorian rules post-1752CAL_EASTER_ROMAN Integer Calculate Easter per Gregorian rules post-1582CAL_EASTER_ALWAYS_GREGORIAN Integer Calculate Easter using proleptic Gregorian rulesCAL_EASTER_ALWAYS_JULIAN Integer Calculate Easter using Julian rulesCAL_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)