I l@ve RuBoard Previous Section Next Section

jdtogregorian

string jdtogregorian(int JD) 

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

Returns:

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

Description:

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.

Version:

3+, 4+

See also:

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

gregoriantojd() 

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

Example:

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."; 
    I l@ve RuBoard Previous Section Next Section