PHP cal_from_jd() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Calendar

Definition

In PHP, cal_from_jd() converts a Julian Day number into calendar date details in one array.

The array includes the date as text, the month, day and year numbers, the day of the week, and both short and long names for the day and the month. It is a one-stop function when you want to show a date in a friendly way.

Syntax

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

PHP
$info = cal_from_jd($jd, CAL_GREGORIAN);
CallWhat it does
cal_from_jd(2451545, CAL_GREGORIAN)Returns an array describing 1/1/2000, a Saturday in January.
cal_from_jd(2451545, CAL_JULIAN)Returns an array for the same day written as 12/19/1999 in the Julian calendar.
cal_from_jd(gregoriantojd(7, 4, 2024), CAL_GREGORIAN)['dayname']Returns Thursday, the weekday of July 4, 2024.

A Julian Day is simply a count of days, so the same number can be shown in different calendars. The returned array has the keys date, month, day, year, dow, abbrevdayname, dayname, abbrevmonth and monthname. In dow, 0 means Sunday.

Library declarations
PHP
cal_from_jd(int $julian_day, int $calendar): array

Parameters

ParameterDescription
julian_dayRequired. The Julian Day number to convert, for example 2451545 for January 1, 2000 in the Gregorian calendar.
calendarRequired. The calendar to convert into. Pass CAL_GREGORIAN (0), CAL_JULIAN (1), CAL_JEWISH (2) or CAL_FRENCH (3).

Return Value

Return ValueDescription
arrayAn array with the keys date (as month/day/year text), month, day, year, dow, abbrevdayname, dayname, abbrevmonth and monthname.

PHP Examples

Example 1 — Everything About a Date

Convert the Julian Day for January 1, 2000 into a Gregorian date and print the whole array.

PHP
<?php
$jd = gregoriantojd(1, 1, 2000);
$info = cal_from_jd($jd, CAL_GREGORIAN);

print_r($info);

How It Works

  1. gregoriantojd() turns January 1, 2000 into the Julian Day number 2451545.
  2. cal_from_jd() converts that number back into a Gregorian date.
  3. The date key holds the text 1/1/2000, and month, day and year hold the separate numbers.
  4. dow is 6, which means Saturday, and the day and month names are also included.

Example 2 — Same Day, Two Calendars

One Julian Day can have different dates in the Gregorian and Julian calendars, but the weekday is always the same.

PHP
<?php
$jd = 2451545;

foreach ([CAL_GREGORIAN, CAL_JULIAN] as $calendar) {
    $info = cal_from_jd($jd, $calendar);
    echo $info['date'], ' - ', $info['dayname'], ', ', $info['monthname'], PHP_EOL;
}

How It Works

  1. The same Julian Day number is used for both conversions.
  2. In the Gregorian calendar it is January 1, 2000.
  3. In the Julian calendar the same day is December 19, 1999, which is 13 days behind.
  4. The weekday stays Saturday because the day itself has not changed, only its label.

Example 3 — Print a Few Days in a Row

Add 1 to a Julian Day to move to the next day, and read the day name from the array.

PHP
<?php
$start = gregoriantojd(1, 1, 2000);

for ($i = 0; $i < 3; $i++) {
    $info = cal_from_jd($start + $i, CAL_GREGORIAN);
    echo $info['date'], ' is ', $info['dayname'], PHP_EOL;
}

How It Works

  1. Julian Day numbers go up by exactly 1 for each new day.
  2. The loop adds 0, 1 and 2 to the starting number.
  3. Each number is converted with cal_from_jd() into a full date array.
  4. We print the date text and the dayname value from each array.

Frequently Asked Questions

It returns an array with the date as text, the month, day and year numbers, the day of the week number (dow), the short and long day names, and the short and long month names.
It is a simple count of days that has been used by astronomers for a long time. Because it is one plain number, it is a handy middle step when you convert between different calendars.
dow is the day of the week as a number. It starts at 0 for Sunday, so 1 is Monday and 6 is Saturday.
Use gregoriantojd() for Gregorian dates, or cal_to_jd() with a calendar constant. Then you can pass that number to cal_from_jd() or to other conversion functions.
Yes, the calendar extension must be enabled. If the function is undefined, turn on extension=calendar in php.ini or install the php-calendar package.

Next: cal_info()

cal_info() returns information about a calendar, such as its name, its month names and the.

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