PHP juliantojd() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Calendar

Definition

In PHP, juliantojd() converts a date in the Julian calendar into a Julian Day number.

The Julian calendar is the old calendar that came before the Gregorian one. Some churches still use it. This function lets you take a date from that calendar and turn it into a number, which you can then convert to a Gregorian date with jdtogregorian().

Syntax

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

PHP
$jd = juliantojd(12, 19, 1999);
CallWhat it does
juliantojd(12, 19, 1999)Returns 2451545, the same day as January 1, 2000 in the Gregorian calendar.
juliantojd(10, 5, 1582)Returns 2299161, the first day of the Gregorian calendar.
juliantojd(1, 1, 0)Returns 0 because year 0 does not exist.

The argument order is month, day, year. The Julian calendar has a leap year every 4 years, including 1900, which is not a leap year in the Gregorian calendar.

Library declarations
PHP
juliantojd(int $month, int $day, int $year): int

Parameters

ParameterDescription
monthRequired. The month as a number from 1 to 12.
dayRequired. The day of the month from 1 to 31.
yearRequired. The year in the Julian calendar. Year 0 does not exist, and negative years are BC.

Return Value

Return ValueDescription
intThe Julian Day number for the date. It returns 0 if the input is not valid.

PHP Examples

Example 1 — Julian Date to Julian Day

Convert two Julian calendar dates and compare them with the matching Gregorian dates.

PHP
<?php
echo juliantojd(10, 5, 1582), PHP_EOL;
echo gregoriantojd(10, 15, 1582), PHP_EOL;
echo juliantojd(12, 19, 1999), PHP_EOL;
echo gregoriantojd(1, 1, 2000), PHP_EOL;

How It Works

  1. October 5, 1582 in the Julian calendar is the same day as October 15, 1582 in the Gregorian calendar.
  2. Both functions return 2299161 because the day itself is the same.
  3. December 19, 1999 in the Julian calendar is January 1, 2000 in the Gregorian calendar.
  4. Both return 2451545, so the two calendars agree on the Julian Day.

Example 2 — Leap Day 1900 and Year 0

The year 1900 was a leap year in the Julian calendar but not in the Gregorian one. Year 0 is not valid.

PHP
<?php
$jd = juliantojd(2, 29, 1900);

echo $jd, PHP_EOL;
echo jdtogregorian($jd), PHP_EOL;
var_dump(juliantojd(1, 1, 0));
var_dump(checkdate(2, 29, 1900));

How It Works

  1. February 29, 1900 exists in the Julian calendar, so we get a valid Julian Day.
  2. In the Gregorian calendar that same day is March 13, 1900.
  3. There is no year 0, so juliantojd() returns 0.
  4. checkdate() uses Gregorian rules, so it says February 29, 1900 does not exist.

Example 3 — Orthodox Christmas in Gregorian Terms

Convert December 25 in the Julian calendar into a Gregorian date and weekday.

PHP
<?php
$jd = juliantojd(12, 25, 2023);

echo $jd, PHP_EOL;
echo jdtogregorian($jd), PHP_EOL;
echo jddayofweek($jd, CAL_DOW_LONG), PHP_EOL;

How It Works

  1. juliantojd(12, 25, 2023) is Christmas Day in the Julian calendar.
  2. The Julian Day number is 2460317.
  3. jdtogregorian() shows that this day is January 7, 2024 in the Gregorian calendar.
  4. jddayofweek() with mode 1 returns the full weekday name, which is Sunday.

Frequently Asked Questions

It converts a date in the Julian calendar into a Julian Day number, which is a plain count of days.
No. The Julian calendar is an old calendar with leap years every 4 years. A Julian Day is just a count of days. The names are alike but they are different things.
Call juliantojd() to get the Julian Day, and then call jdtogregorian() on the result.
The month, day or year is not valid, for example year 0 or month 13. Check your input before calling the function.
Yes. If PHP says juliantojd() is undefined, enable extension=calendar in php.ini or install the php-calendar package.

Next: unixtojd()

unixtojd() converts a Unix timestamp into a Julian Day number.

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