PHP jdtogregorian() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Calendar

Definition

In PHP, jdtogregorian() converts a Julian Day number into a Gregorian month/day/year string.

It is the reverse of gregoriantojd(). After doing date math with Julian Day numbers, you use jdtogregorian() to turn the answer back into a date that people can read.

Syntax

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

PHP
$date = jdtogregorian($jd);
CallWhat it does
jdtogregorian(2451545)Returns 1/1/2000.
jdtogregorian(2460670)Returns 12/25/2024.
jdtogregorian(0)Returns 0/0/0 because the number is not a valid date.

The result is month/day/year with no leading zeros, like 1/1/2000, so it is not ready for a database. Split it with explode('/') and format it with sprintf() when you need a format like 2000-01-01.

Library declarations
PHP
jdtogregorian(int $julian_day): string

Parameters

ParameterDescription
julian_dayRequired. The Julian Day number to convert, such as 2451545.

Return Value

Return ValueDescription
stringThe Gregorian date as month/day/year text. It returns 0/0/0 for a Julian Day of zero or below.

PHP Examples

Example 1 — Julian Day to Date

Convert a few Julian Day numbers into readable Gregorian dates.

PHP
<?php
echo jdtogregorian(2451545), PHP_EOL;
echo jdtogregorian(2460311), PHP_EOL;
echo jdtogregorian(2460670), PHP_EOL;
echo jdtogregorian(gregoriantojd(7, 4, 2024)), PHP_EOL;

How It Works

  1. 2451545 is the Julian Day for January 1, 2000.
  2. 2460311 is the Julian Day for January 1, 2024.
  3. 2460670 is 359 days later, which is December 25, 2024.
  4. Converting a date to a number and back gives you the same date.

Example 2 — Invalid Numbers

A Julian Day of zero or below is not a valid date, so PHP returns the text 0/0/0 instead of an error.

PHP
<?php
echo jdtogregorian(0), PHP_EOL;
echo jdtogregorian(-5), PHP_EOL;
echo jdtogregorian(2299161), PHP_EOL;
var_dump(jdtogregorian(0) === '0/0/0');

How It Works

  1. Julian Day 0 is not a valid date, so the result is 0/0/0.
  2. A negative number is also invalid and gives the same text.
  3. A valid number such as 2299161 returns a normal date, October 15, 1582, the first day of the Gregorian calendar.
  4. You can test for an invalid result by comparing against the text '0/0/0'.

Example 3 — Format as YYYY-MM-DD

Split the month/day/year text and rebuild it in the ISO format that databases like.

PHP
<?php
$jd = gregoriantojd(12, 25, 2024) + 30;

[$month, $day, $year] = explode('/', jdtogregorian($jd));
echo 'Raw: ', jdtogregorian($jd), PHP_EOL;
echo 'ISO: ', sprintf('%04d-%02d-%02d', $year, $month, $day), PHP_EOL;

How It Works

  1. We start with December 25, 2024 and add 30 days to the Julian Day number.
  2. jdtogregorian() returns the text 1/24/2025 for the new day.
  3. explode('/') splits it into month, day and year.
  4. sprintf() pads the month and day with zeros to build 2025-01-24.

Frequently Asked Questions

It converts a Julian Day number into a Gregorian date and returns it as text in the form month/day/year.
Split the result with explode('/') and use sprintf('%04d-%02d-%02d', $year, $month, $day) to build the ISO format with leading zeros.
The Julian Day is zero or negative, so it does not map to a valid date. Check the number that you pass in.
gregoriantojd() does the opposite. It takes a month, a day and a year and returns the Julian Day number.
Yes. If PHP says jdtogregorian() is undefined, enable extension=calendar in php.ini or install the php-calendar package.

Next: jdtojewish()

jdtojewish() converts a Julian Day number into a Jewish (Hebrew) date string.

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