| by Arround The Web | No comments

How to Use cal_to_jd() Function in PHP?

The cal_to_jd() is a PHP function used to convert a given date into a Julian Day Count. With the help of the cal_to_jd() function, we can determine how many Julian days are on a given date in the chosen calendar. This function is supported by PHP version 4.1 and later. The function accepts four mandatory parameters and returns the Julian day number.

Syntax for cal_to_jd() Function

The cal_to_jd() function in PHP follows the simple syntax given below:

cal_to_jd(calendar, month, day, year)

 
This syntax shows that the function takes four inputs, which are:

    • calendar: A mandatory argument that specifies a calendar value such as CAL_GREGORIAN, CAL_JEWISH, CAL_JULIAN, and CAL_FRENCH.
    • month: A mandatory argument that specifies an integer value for the month. Its range depends on the specified calendar.
    • day: A mandatory argument that specifies an integer value for the day. Its range depends on the specified calendar.
    • year: A mandatory argument that specifies an integer value for the year. Its range depends on the specified calendar.

Return Value: This function provides a Julian day number as an output.

Example 1

This is a simple PHP code that calls the GREGORIAN calendar to calculate a Julian number from its specified date using the PHP cal_to_jd() function.

< ?php
$date = cal_to_jd(CAL_GREGORIAN, 10, 03, 2010);
echo "The Julian day count is: ", $date;
?>

 

Example 2

This is a simple PHP code that calls the JEWISH calendar to calculate a Julian number from its specified date using PHP cal_to_jd() function.

< ?php
$date = cal_to_jd(CAL_JEWISH, 10, 03, 2010);
echo "The Julian day count is: ", $date;
?>

 

Example 3

The following code calls the FRENCH calendar to calculate a Julian number from its specified date using PHP cal_to_jd() function.

< ?php
$date = cal_to_jd(CAL_FRENCH, 10, 03, 12);
echo "The Julian day count is: ", $date;
?>

 

Conclusion

The built-in cal_to_jd() function in PHP determines the Julian day count using the date from the specified calendar. This function supports four calendars that are CAL_GREGORIAN, CAL_JEWISH, CAL_JULIAN, and CAL_FRENCH. The function accepts four parameters and returns a calculated Julian day count as an integer value. This tutorial elaborated on the functionality of the PHP cal_to_jd() function with examples.

Share Button

Source: linuxhint.com

Leave a Reply