Skip to content

Instantly share code, notes, and snippets.

@dovidezra
Last active April 26, 2022 01:10
Show Gist options
  • Save dovidezra/a4f66067c9389869804631c20887cdc8 to your computer and use it in GitHub Desktop.
Save dovidezra/a4f66067c9389869804631c20887cdc8 to your computer and use it in GitHub Desktop.
PHP: Covert Current Gregorian Date to Jewish Calendar Date
<?php
$month = date('m');
$day = date('d');
$year = date('Y');
function isJewishLeapYear($year) {
if ($year % 19 == 0 || $year % 19 == 3 || $year % 19 == 6 ||
$year % 19 == 8 || $year % 19 == 11 || $year % 19 == 14 ||
$year % 19 == 17)
return true;
else
return false;
}
function getJewishMonthName($jewishMonth, $jewishYear) {
$jewishMonthNamesLeap = array("Tishri", "Heshvan", "Kislev", "Tevet",
"Shevat", "Adar I", "Adar II", "Nisan",
"Iyar", "Sivan", "Tammuz", "Av", "Elul");
$jewishMonthNamesNonLeap = array("Tishri", "Heshvan", "Kislev", "Tevet",
"Shevat", "", "Adar", "Nisan",
"Iyar", "Sivan", "Tammuz", "Av", "Elul");
if (isJewishLeapYear($jewishYear))
return $jewishMonthNamesLeap[$jewishMonth-1];
else
return $jewishMonthNamesNonLeap[$jewishMonth-1];
}
$jdNumber = gregoriantojd($month,$day,$year);
$jewishDate = jdtojewish($jdNumber);
list($jewishMonth, $jewishDay, $jewishYear) = explode('/', $jewishDate);
$jewishMonthName = getJewishMonthName($jewishMonth, $jewishYear);
echo "<p>$jewishDay $jewishMonthName $jewishYear</p>\n";
?>
@dovidezra
Copy link
Author

OUTPUT EXAMPLE: 24 Nisan 5782

@dovidezra
Copy link
Author

Works with LEAP years

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment