W3docs

jdtojulian()

Learn how the PHP jdtojulian() function converts a Julian Day Count to a Julian calendar date string, with working examples and the reverse juliantojd().

The PHP jdtojulian() Function

The jdtojulian() function converts a Julian Day Count into a date in the Julian calendar, returned as a string in the format month/day/year.

It is important not to confuse the two meanings of the word "Julian" here:

  • Julian Day Count (JDC) — a continuous count of days since noon Universal Time on January 1, 4713 BC. It is just a number (for example, 2459459) and has nothing to do with any particular calendar. It is widely used in astronomy because it makes date arithmetic simple.
  • Julian calendar — the calendar introduced by Julius Caesar in 45 BC, used across Europe until it was gradually replaced by the Gregorian calendar starting in 1582. Today the two calendars differ by 13 days.

jdtojulian() takes a Julian Day Count and tells you which date that count corresponds to in the Julian calendar. Its counterpart, jdtogregorian(), does the same but returns the date in the Gregorian calendar.

Syntax

jdtojulian(int $julian_day): string

It accepts one parameter — the Julian Day Count as an integer — and returns the corresponding Julian calendar date as a "month/day/year" string. If the input is 0 (an invalid Julian day), it returns "0/0/0".

Converting a Julian Day Count to a Julian Calendar Date

<?php

$jdc = 2459459;
$julianDate = jdtojulian($jdc);

echo $julianDate; // Outputs: 8/19/2021

The returned value is a string, so you can split it apart when you need the individual parts:

<?php

[$month, $day, $year] = explode('/', jdtojulian(2459459));

echo "Year: $year, Month: $month, Day: $day";
// Outputs: Year: 2021, Month: 8, Day: 19

Why the Julian and Gregorian dates differ

The same Julian Day Count maps to a different label in each calendar. For 2459459:

<?php

echo jdtojulian(2459459);    // Outputs: 8/19/2021  (Julian calendar)
echo "\n";
echo jdtogregorian(2459459); // Outputs: 9/1/2021   (Gregorian calendar)

The 13-day gap between 8/19 and 9/1 is exactly the current offset between the Julian and Gregorian calendars — both rows describe the very same instant in time.

Converting a Julian Calendar Date Back to a Julian Day Count

To go the other way — from a Julian calendar date back to a Julian Day Count — use juliantojd(). It takes the month, day, and year and returns an integer:

<?php

$jdc = juliantojd(8, 19, 2021);

echo $jdc; // Outputs: 2459459

Because the two functions are inverses, a round trip returns the original date:

<?php

echo jdtojulian(juliantojd(8, 19, 2021)); // Outputs: 8/19/2021

When Would I Use This?

You rarely need the Julian calendar for everyday application dates — for those, prefer PHP's DateTime and date() APIs, which work in the Gregorian calendar. jdtojulian() is useful when you are:

  • Working with historical records dated before the Gregorian reform of 1582 (or in countries that adopted it much later).
  • Interfacing with astronomical or genealogical data that stores dates as Julian Day Counts.
  • Converting between calendar systems where the Julian Day Count acts as a neutral pivot — for example, gregoriantojd() → store the integer → jdtojulian().

Note: The calendar extension must be enabled for these functions to be available. It is bundled with PHP and compiled in by default on most builds.

Conclusion

The jdtojulian() function converts a Julian Day Count into a date string in the Julian calendar, while juliantojd() performs the reverse. They mirror the Gregorian pair, jdtogregorian() and gregoriantojd(), which is why the same day count yields two different calendar labels. For full details, see the official jdtojulian() and juliantojd() documentation.

Practice

Practice
What is the role of the jdtojulian() function in PHP?
What is the role of the jdtojulian() function in PHP?
Was this page helpful?