cal_to_jd: getting Julian day count

Convert a calendar date to a Julian Day count

cal_to_jd() accepts a calendar constant plus month, day and year.

$jd = cal_to_jd(CAL_GREGORIAN, 9, 14, 2026);
echo $jd;
$day = cal_to_jd(CAL_GREGORIAN,2,2,2103);
echo $day;
The output is 2489197

Syntax
cal_to_jd($calendar, $month, $day, $year)
In the above code the list of calendar are CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH and CAL_FRENCH.

Example: Converting Gregorian Date to Julian Day

$jd = cal_to_jd(CAL_GREGORIAN, 10, 8, 2023);
echo "Julian Day: " . $jd;  // Output: Julian Day: 2460219

Validate a Gregorian date before conversion

cal_to_jd() returns a Julian Day count; it is not a Gregorian date validator. When user input represents a Gregorian date, validate it with checkdate() first.

$month = 2;
$day = 30;
$year = 2023;

if (checkdate($month, $day, $year)) {
    $jd = cal_to_jd(CAL_GREGORIAN, $month, $day, $year);
    echo "Julian Day: " . $jd;
} else {
    echo "Invalid Gregorian date";
}

Read how cal_to_jd function is used to get weekday
Demo of how Unix timestamp is used to generate Julian Day and Calendar
Calendar Functions


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer