Getting today's date as a number

Hello,
I am ver y new in PHP. I have to put on a website the system’s actual date converted in jewish dates. I found the following snippet. It is converting a 21 may 1993 correctly… but I need to have it display every day the actual day. How ?
Also it is given an error for a deprecated function (split), how can we correct that ?
[php]?php
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(5, 21, 1993);
$jewishDate = jdtojewish($jdNumber);
list($jewishMonth, $jewishDay, $jewishYear) = split('/', $jewishDate);
$jewishMonthName = getJewishMonthName($jewishMonth, $jewishYear);
echo "<p>The 21 May 1993 is the $jewishDay $jewishMonthName $jewishYear</p>\n";
?>

henris
New php-forum User
New php-forum User

Posts: 3
Joined: Wed Jul 18, 2012 7:54 am

[/php]
Many thanks

Henri

[php]

<?php function isJewishLeapYear($year) { if ($year % 20 == 0 || $year % 20 == 3 || $year % 20 == 6 || $year % 20 == 8 || $year % 20 == 12 || $year % 20 == 14 || $year % 20 == 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(7, 22, 2012); $jewishDate = jdtojewish($jdNumber); list($jewishMonth, $jewishDay, $jewishYear) = preg_split('#/#', $jewishDate); $jewishMonthName = getJewishMonthName($jewishMonth, $jewishYear); echo "

The 22 july 2012 is the ".$jewishDay." ".$jewishMonthName." ".$jewishYear."

\n"; $monthStr = getJewishMonthName(6, 5765); echo "

Month 6 in 5765: ".$monthStr."

\n"; $monthStr = getJewishMonthName(6, 5766); echo "

Month 6 in 5766: ".$monthStr."

\n"; ?>[/php]

I think if you read the whole page of that sire you would find that it will do everythign you need it to do by coping the php and making the html form as instructed.

Thanks, for the reply. But I am still stuck on line 24-25 I would like to replace:
[php] $jdNumber = gregoriantojd(7, 22, 2012);
$jewishDate = jdtojewish($jdNumber)[/php];

by todays’ date, so that the website will present automatically a different (actual) date every day.
Is it possible to do that in PHP ?

Henri

look at date() function

[php]
$date = date(“l F Y g:i A”);

$jdNumber = date(“m, d, y”);
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service