PHP Calendar Functions

About This Index
This page is the PHP Calendar Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn how the calendar extension and the Julian Day number fit together on /php/calendar. Use this page when you need a specific function such as cal_days_in_month(), cal_to_jd(), or easter_date().
Start with cal_days_in_month()—then learn cal_to_jd() and cal_from_jd(), and finish with easter_days() and easter_date().
These functions come from the calendar extension. If one is undefined on your server, check extension_loaded('calendar'). When it returns false, enable the extension in your PHP build or package and restart PHP.
How to Call a PHP Calendar Function
Every calendar helper is a global function—call it directly. Dates are given as month, day, year, and the generic functions take a calendar constant such as CAL_GREGORIAN:
echo cal_days_in_month(CAL_GREGORIAN, 2, 2024); // 29
$jd = gregoriantojd(1, 15, 2024); // 2460325
echo jdtogregorian($jd); // 1/15/2024
echo jddayofweek($jd, 1); // Monday
$same = cal_to_jd(CAL_GREGORIAN, 1, 15, 2024); // 2460325
$parts = cal_from_jd($same, CAL_GREGORIAN);
echo $parts['monthname']; // January
echo easter_days(2024); // 10 PHP Calendar Functions Table
All function guides in this PHP tutorial series (18 tutorials in 6 categories).
Calendar info
2 functionsRead facts about a calendar and the length of its months. Pass a calendar constant such as CAL_GREGORIAN.
| Function | Description | Tutorial |
|---|---|---|
cal_info() | Get month names, month count, and other details of a calendar. | Try it |
cal_days_in_month() | Get the number of days in a month for a calendar and year. | Try it |
Julian Day bridge
2 functionsTurn a date from any supported calendar into a Julian Day number, and turn the number back into date parts. This is the hub every other converter uses.
| Function | Description | Tutorial |
|---|---|---|
cal_to_jd() | Convert a date in a given calendar to a Julian Day number. | Try it |
cal_from_jd() | Convert a Julian Day number to an array of date parts and names. | Try it |
Easter
2 functionsFind Easter Sunday for a year. easter_days() counts days after March 21; easter_date() returns a Unix timestamp.
| Function | Description | Tutorial |
|---|---|---|
easter_date() | Get the Unix timestamp of midnight on Easter Sunday. | Try it |
easter_days() | Get the number of days between March 21 and Easter Sunday. | Try it |
Gregorian/Julian convert
4 functionsConvert between a Julian Day number and a date in the Gregorian or Julian calendar. The date order is month, day, year.
| Function | Description | Tutorial |
|---|---|---|
gregoriantojd() | Convert a Gregorian date to a Julian Day number. | Try it |
jdtogregorian() | Convert a Julian Day number to a Gregorian date string. | Try it |
juliantojd() | Convert a Julian calendar date to a Julian Day number. | Try it |
jdtojulian() | Convert a Julian Day number to a Julian calendar date string. | Try it |
Jewish/French
4 functionsConvert between a Julian Day number and a date in the Jewish or French Republican calendar. The French calendar only covers years 1 to 14.
| Function | Description | Tutorial |
|---|---|---|
jewishtojd() | Convert a Jewish calendar date to a Julian Day number. | Try it |
jdtojewish() | Convert a Julian Day number to a Jewish calendar date. | Try it |
frenchtojd() | Convert a French Republican date to a Julian Day number. | Try it |
jdtofrench() | Convert a Julian Day number to a French Republican date string. | Try it |
Day helpers & Unix
4 functionsGet the weekday or month name of a Julian Day, and move between Julian Day numbers and Unix timestamps.
| Function | Description | Tutorial |
|---|---|---|
jddayofweek() | Get the day of the week of a Julian Day as a number or a name. | Try it |
jdmonthname() | Get the month name of a Julian Day for a calendar mode. | Try it |
jdtounix() | Convert a Julian Day number to a Unix timestamp. | Try it |
unixtojd() | Convert a Unix timestamp to a Julian Day number. | Try it |
Frequently Asked Questions
Start with cal_days_in_month()
Open the first guide—syntax, examples, and FAQs.
6 people found this page helpful
