Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP - Calendar jdtogregorian() Function



The PHP Calendar jdtogregorian() function is used to convert Julian Day Count to a string containing the Gregorian date in the format of "month/day/year". This function is very useful when you want to change Julian dates into the Gregorian calendar dates.

Syntax

Below is the syntax of the PHP Calendar jdtogregorian() function −

string jdtogregorian ( $jd );

Parameters

This function accepts $jd parameter which is a Julian day number as integer.

Return Value

The jdtogregorian() function returns the he gregorian date as a string in the form "month/day/year".

PHP Version

First introduced in core PHP 4, the jdtogregorian() function continues to function easily in PHP 5, PHP 7, and PHP 8.

Example 1

First we will show you the basic example of the PHP Calendar jdtogregorian() function to convert a single Julian day number into the matching Gregorian date.

<?php
   // Julian day for January 1, 2000
   $jd = 2451545; 
   
   // Convert the gregorian date to Julian Day
   $gregorian_date = jdtogregorian($jd);
   
   // Display the result
   echo "The Gregorian Date: ".$gregorian_date; 
?>

Output

Here is the outcome of the following code −

The Gregorian Date: 01/01/2000

Example 2

In the below PHP code we will use the jdtogregorian() function and show how to convert today's date from Julian day to Gregorian date.

<?php
   // Convert Julian Date to Gregorian date
   $jd = gregoriantojd(8, 14, 2024); 

   // Convert the gregorian date to Julian Day
   $gregorian_date = jdtogregorian($jd);

   // Display the result
   echo $gregorian_date; 
?> 

Output

This will generate the below output −

The Gregorian Date: 08/14/2024

Example 3

Here is the historical Julian day is changed into a Gregorian date with the help of jdtogregorian() function.

<?php
   // Julian day before the Gregorian calendar reform
   $julian_day = 2299161; 

   // Convert the gregorian date to Julian Day
   $gregorian_date = jdtogregorian($julian_day);

   // Display the result
   echo $gregorian_date; 
?> 

Output

This will create the below output −

The Gregorian Date: 10/15/1582

Example 4

Here is the example in which we are converting the Julian day to gregorian day and vice versa using the jdtogregorian() and gregoriantojd() functions for the same date.

<?php
   // Julian day before the Gregorian calendar reform
   $jd = gregoriantojd(1, 12, 1990);
   echo "Here is the Julian Day - $jd \n";
   
   $gregorian = jdtogregorian($jd);
   echo "Here is the Gregorian Day - $gregorian \n";
?> 

Output

Following is the output of the above code −

Here is the Julian Day - 2447904 
Here is the Gregorian Day - 1/12/1990 
php_function_reference.htm
Advertisements