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);
Call
What 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.
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
Parameter
Description
julian_day
Required. The Julian Day number to convert, for example 2451545 for January 1, 2000 in the Gregorian calendar.
calendar
Required. The calendar to convert into. Pass CAL_GREGORIAN (0), CAL_JULIAN (1), CAL_JEWISH (2) or CAL_FRENCH (3).
Return Value
Return Value
Description
array
An 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.
1/1/2000 is Saturday
1/2/2000 is Sunday
1/3/2000 is Monday
How It Works
Julian Day numbers go up by exactly 1 for each new day.
The loop adds 0, 1 and 2 to the starting number.
Each number is converted with cal_from_jd() into a full date array.
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.