PHP - Calendar cal_to_jd() Function
The PHP Calendar cal_to_jd() function is used to calculate the Julian day count for a date in the specified calendar. The Julian Day Count is a running total of days since the beginning of the Julian period. This function is useful when you have to work with dates from many calendar systems.
Syntax
Below is the syntax of the PHP Calendar cal_to_jd() function −
int cal_to_jd ( $calendar, $month, $day, $year )
Parameters
Below are the parameters of the cal_to_jd() function −
$calendar − It is the calendar to use for calculation. These calendar values can be used − CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH, CAL_FRENCH.
$month − It is the month in the selected calendar.
$day − It is the day in the selected calendar.
$year − It is the year in the selected calendar.
Return Value
The cal_to_jd() function returns the length in days of the selected month in the given calendar.
PHP Version
First introduced in core PHP 4.1.0, the cal_to_jd() 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 cal_to_jd() function to convert a gregorian date to Julian day count.
<?php // Convert a Gregorian Date to Julian Day Count $d = cal_to_jd(CAL_GREGORIAN, 11, 03, 2024); // Display the result echo "Julian Day Count is as follows: ".$d; ?>
Output
Here is the outcome of the following code −
Julian Day Count is as follows: 2460618
Example 2
In the below PHP code we will use the cal_to_jd() function and convert a Jewish date to Julian Day Count.
<?php // Convert a Jewish date to Julian Day Count $d = cal_to_jd(CAL_JEWISH, 1, 1, 5785); // Display the result echo "Julian Day Count is as follows: ".$d; ?>
Output
This will generate the below output −
Julian Day Count is as follows: 2460209
Example 3
This example shows how to convert a date from the French republican calendar to Julian Day Count using the cal_to_jd() function.
<?php // Convert a French republican date to Julian Day Count $d = cal_to_jd(CAL_FRENCH, 1, 1, 1); // Display the result echo "Julian Day Count is as follows: ".$d; ?>
Output
This will create the below output −
Julian Day Count is as follows: 2375840