What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.



jdtogregorian — Converts a Julian day count to a Gregorian calendar date of the format MM/DD/YY.


string jdtogregorian(JD);
int JD: Julian day count


Gregorian calendar date; 0/0/0 if JD is not a valid Julian day count


jdtogregorian() converts a Julian day count to a Gregorian calendar date. The date is returned as a string with the format MM/DD/YY. If an invalid Julian day count is specified, the function returns 0/0/0.


PHP Version: 3+, 4+

See also

To convert a Gregorian calendar date to a Julian day count:


To get a Julian day count from another calendar system, see the various *tojd() functions.


Example 76. Convert a Julian calendar date to a Gregorian calendar date

// Write a function to add the proper ordinal suffix to a number
function add_ordinal_suffix ($number) {
    $last_2_digits = substr (0, -2, $number);
    if (($number % 10) == 1 && $last_2_digits != 11)
        return $number.'st';
    if (($number % 10) == 2 && $last_2_digits != 12)
        return $number.'nd';
    if (($number % 10) == 3 && $last_2_digits != 13)
        return $number.'rd';
    return $number.'th'; //default suffix

    Use the birthdate of Sir Isaac Newton as the Julian calendar date.
    England did not adopt the Gregorian calendar until 1752,
    hence some old texts cite Newton's birthday as December 25, 1642.

// Find the Julian day count for Newton's birthday
$julian_day = juliantojd (12, 25, 1642);

// Find the number of days between today and Newton's birthdate
$difference = unixtojd () - $julian_day;

// Convert $julian_day to a gregorian date
// Parse year, month, and day into separate variables
list ($month, $day, $year) = explode ('/', jdtogregorian ($julian_day));

// Add an ordinal suffix to $month and $day
$day = add_ordinal_suffix ($day);
$month = add_ordinal_suffix ($month);

echo "Sir Isaac Newton was born $difference days ago on the $day day of the $month month of $year.";

PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at The authors of this book have elected not to choose any options under the OPL. This online book was obtained from and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.