PHP Calendar Functions

Beginner
4 min read
Updated: Nov 2026
18 function guides
Function index

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().

Beginner path.

Start with cal_days_in_month()—then learn cal_to_jd() and cal_from_jd(), and finish with easter_days() and easter_date().

The extension may need enabling.

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:

PHP
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 functions

Read facts about a calendar and the length of its months. Pass a calendar constant such as CAL_GREGORIAN.

FunctionDescriptionTutorial
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 functions

Turn 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.

FunctionDescriptionTutorial
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 functions

Find Easter Sunday for a year. easter_days() counts days after March 21; easter_date() returns a Unix timestamp.

FunctionDescriptionTutorial
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 functions

Convert between a Julian Day number and a date in the Gregorian or Julian calendar. The date order is month, day, year.

FunctionDescriptionTutorial
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 functions

Convert between a Julian Day number and a date in the Jewish or French Republican calendar. The French calendar only covers years 1 to 14.

FunctionDescriptionTutorial
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 functions

Get the weekday or month name of a Julian Day, and move between Julian Day numbers and Unix timestamps.

FunctionDescriptionTutorial
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

They are the functions of the calendar extension. They count the days in a month, convert dates between the Gregorian, Julian, Jewish, and French Republican calendars through a Julian Day number, find the date of Easter, and return weekday and month names for a Julian Day.
The Calendar page teaches the ideas: the calendar extension, the Julian Day number as a hub, month lengths, and Easter, with fixed 2024 examples. This index lists every function tutorial so you can open cal_days_in_month(), cal_to_jd(), easter_date(), and the rest.
Start with cal_days_in_month() for a simple, useful result. Then learn cal_to_jd() and cal_from_jd(), which show how the Julian Day number connects every calendar, followed by easter_days() and easter_date().
Both return a Julian Day number. gregoriantojd($month, $day, $year) works only for the Gregorian calendar. cal_to_jd($calendar, $month, $day, $year) takes a calendar constant such as CAL_GREGORIAN or CAL_JEWISH, so one function covers all four calendars. The same pairing exists for cal_from_jd() and jdtogregorian().
Go through the Julian Day number. Call gregoriantojd() to get the number, then pass it to jdtojewish() or jdtojulian(). To go the other way, call jewishtojd() or juliantojd() and then jdtogregorian().
The calendar extension may not be loaded. Run var_dump(extension_loaded('calendar')); to check. If it prints false, enable the extension in your PHP build or package (for a source build, use --enable-calendar) and restart PHP.

Start with cal_days_in_month()

Open the first guide—syntax, examples, and FAQs.

cal_days_in_month() 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.

6 people found this page helpful