jdtojewish()
Learn how the PHP jdtojewish() function converts a Julian Day Count to a Jewish calendar date, with syntax, flags, examples, and gotchas.
Introduction
The PHP jdtojewish() function converts a Julian Day Count (a continuous, integer day number) into a date in the Jewish (Hebrew) calendar. It is part of PHP's Calendar extension and is the inverse of jewishtojd().
This page covers the function's syntax, its parameters and return value, the optional Hebrew-formatting flags, a working example, and the common pitfalls to watch for.
What is a Julian Day Count?
A Julian Day Count (JDC) is a continuous count of whole days since noon on January 1st, 4713 BC (in the proleptic Julian calendar). Because every date — past or future — maps to a single integer, the JDC is a convenient neutral representation: you convert any calendar date into a Julian Day, then out again into another calendar. This is exactly how PHP's calendar conversion functions work: each calendar has a *tojd() function and a jdto*() function.
Note that "Julian Day" is unrelated to the "Julian calendar" — they only share a name.
Syntax
jdtojewish(int $julian_day, bool $hebrew = false, int $flags = 0): string| Parameter | Description |
|---|---|
$julian_day | The Julian Day Count to convert. Must be an integer. |
$hebrew | If true, return the date as Hebrew text instead of month/day/year. |
$flags | A bitmask of formatting constants (see below). Only used when $hebrew is true. |
Return value: a string. When $hebrew is false, the format is "month/day/year", for example "8/7/5784". When $hebrew is true, the date is rendered as a Hebrew string.
Hebrew formatting flags
These constants can be combined with the | (bitwise OR) operator and only take effect when $hebrew is true:
| Constant | Effect |
|---|---|
CAL_JEWISH_ADD_ALAFIM_GERESH | Add a geresh (') for the thousands. |
CAL_JEWISH_ADD_ALAFIM | Add the word alafim (thousands). |
CAL_JEWISH_ADD_GERESHAYIM | Add gershayim before the last letter of the date. |
Basic example
<?php
// First convert a Gregorian date to a Julian Day Count.
$julianDay = gregoriantojd(8, 7, 2024); // month, day, year
// Then convert that Julian Day to a Jewish calendar date.
$jewishDate = jdtojewish($julianDay);
echo "Julian Day Count: $julianDay\n";
echo "Jewish date (month/day/year): $jewishDate\n";
?>Here we start from the Gregorian date August 7, 2024, turn it into a Julian Day Count with gregoriantojd(), and then feed that count to jdtojewish(). The result is returned in month/day/year form using Jewish-calendar month and year numbers.
Returning a Hebrew string
Pass true as the second argument to render the date in Hebrew text, and combine flags for fuller formatting:
<?php
$julianDay = gregoriantojd(8, 7, 2024);
$hebrew = jdtojewish(
$julianDay,
true,
CAL_JEWISH_ADD_GERESHAYIM | CAL_JEWISH_ADD_ALAFIM_GERESH
);
echo $hebrew;
?>Common gotchas
- Use an integer Julian Day, not a fractional one. Functions like
gregoriantojd()return an integer count. Passing a float such as2459401.5is rejected on modern PHP — always work with whole-day integers. - Flags are ignored unless
$hebrewistrue. TheCAL_JEWISH_*constants only change the output of the Hebrew string form. - The Calendar extension must be available.
jdtojewish()is part of PHP'scalendarextension. It is bundled by default in most distributions, but if the function is undefined, enable/compile the extension.
Related functions
jewishtojd()— the inverse: Jewish date to Julian Day Count.gregoriantojd()— Gregorian date to Julian Day Count.jdtogregorian()— Julian Day Count to Gregorian date.jdmonthname()— month name for a Julian Day in a given calendar.jddayofweek()— day of the week for a Julian Day.
Conclusion
jdtojewish() turns a Julian Day Count into a Jewish calendar date, optionally as Hebrew text. Pair it with gregoriantojd() (or any other *tojd() function) to convert between calendars, remember to pass an integer day count, and reach for the CAL_JEWISH_* flags only when you ask for the Hebrew string form.