
It has been a long while since I last wrote any example scripts on here, but one I have found on Ask a Jew when checking search results is how to convert dates to a Jewish calendar using the PHP language.
If you search online for how to convert a date to the Jewish calendar using PHP, you will quickly notice a pattern. A lot of examples look convincing, use Hebrew month names, and even output Hebrew letters. Unfortunately, most of them are completely wrong.
This usually happens because the code does not actually convert anything. It simply takes a Gregorian date, swaps the English month name for a Jewish one, and sometimes replaces the digits in the year with Hebrew characters. That may look Jewish enough at first glance, but it has nothing to do with how the Jewish calendar works.
The Jewish calendar is not a renamed version of the Gregorian calendar. It uses a different year numbering system, it is lunisolar rather than solar, it has leap months, variable month lengths, and specific rules about when a new month begins. Because of this, Jewish dates move around when compared to the civil calendar we use day to day. The 25th of Kislev does not fall on the same Gregorian date every year. If it did, Chanukah would never move.
This is why so much example code you find online quietly fails. It produces output that looks plausible but is mathematically incorrect.
A common but broken approach
A typical incorrect solution maps month numbers directly to Jewish month names and leaves the day untouched. Sometimes it also converts the year by replacing digits with Hebrew letters. The result might say something like 3 Kislev 2022, but that date almost certainly does not exist in the Jewish calendar.
The fundamental mistake is assuming that month one in the Gregorian calendar lines up with month one in the Jewish calendar. It does not. The calendars are based on different systems entirely.
The correct way to do this in PHP
The good news is that PHP already knows how to handle the Jewish calendar correctly. You do not need to calculate moon cycles yourself, and you do not need a third-party library that may or may not still be maintained.
PHP includes a calendar extension that can convert between calendar systems using Julian Day numbers. This is the same underlying approach used in serious calendar software.
The process is straightforward.
- First, convert the Gregorian date to a Julian Day number.
- Second, convert that Julian Day number to a Jewish date.
Here is a correct and modern example.
$year = 2022;
$month = 12;
$day = 8;
$jd = gregoriantojd($month, $day, $year);
$hebrewDate = cal_from_jd($jd, CAL_JEWISH);
echo $hebrewDate['day'] . " "
. $hebrewDate['monthname'] . " "
. $hebrewDate['year'];
This returns the actual Jewish date according to the rules of the Jewish calendar. The year is correct, the month is correct, and the day is correct. No guesswork, no approximations, and no silent errors.
You can also extract individual parts if you need them separately.
$hebrewYear = $hebrewDate['year'];
$hebrewMonth = $hebrewDate['month'];
$hebrewDay = $hebrewDate['day'];

Join the Discussion
Learn how to convert dates to the Jewish calendar using PHP language correctly, and why the code example provided in this article won't work.