Last active
April 26, 2022 01:10
-
-
Save dovidezra/a4f66067c9389869804631c20887cdc8 to your computer and use it in GitHub Desktop.
PHP: Covert Current Gregorian Date to Jewish Calendar Date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
?> |
Works with LEAP years
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OUTPUT EXAMPLE:
24 Nisan 5782