# An algorithm that counts how many days have passed since a certain date

Good day to all.

Does anyone have an algorithm that counts how many days have passed since a certain date? And does anyone have any ideas how to write it? Are there such functions? It only came to mind to divide days by 365.25, months by 12, and multiply the difference in years by 365.25 … but it turns out not exactly. I want something like:

``````<?
/* YYYYmmdd -     ,  20110920 */
\$today = \$YYYYmmdd;
/* \$amoon -     */
\$moon = 19690721;
/*       )) /*
echo "    ".\$raznica."  .";
?>
``````

## Answer 1, authority 100%

``````\$today = time();
\$moon = mktime(0, 0, 0, 7, 21, 1969);
echo "    ".floor((\$today - \$moon) / 86400)."  .";
``````

## Answer 2, authority 22%

Well, this is very rude. Although I also have a rude enough and did not make decisions for dates that are less than 1970. (It was just laziness.)

``````function vypiska(\$skolko, \$chego)
{
global \$array;
if (\$skolko == 0)
\$skolko = 10;
if (\$skolko == 1)
\$a = 3 * \$chego + 1;
if (\$skolko >= 2 && \$skolko <= 4)
\$a = 3 * \$chego + 2;
if (\$skolko >= 5 && \$skolko <= 20)
\$a = 3 * \$chego + 3;
if (\$skolko > 20 && \$skolko < 100)
return vypiska(\$skolko % 10, \$chego);
if (\$skolko >= 100)
return vypiska(\$skolko % 100, \$chego);
return \$array[\$a];
}
\$array = array(
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
);
\$std   = \$_GET['d'];
\$ed    = mktime(0, 0, 0, date("m,d,Y"));
\$e     = abs(\$ed - \$std);
\$f     = date('j-n-Y', \$e);
\$dat   = explode("-", \$f);
\$day   = \$dat - 1;
\$month = \$dat - 1;
\$year  = \$dat - 1970;
\$soob  = \$text . " ";
if (\$year != 0)
\$soob = \$soob . \$year . " " . vypiska(\$year, 2);
if (\$year != 0 && \$month != 0 && \$day != 0)
\$soob = \$soob . ", ";
if (\$year != 0 && \$month != 0 && \$day == 0)
\$soob = \$soob . "  ";
if (\$month == 0 && \$day != 0 && \$year != 0)
\$soob = \$soob . "  ";
if (\$month != 0)
\$soob = \$soob . \$month . " " . vypiska(\$month, 1);
if (\$month != 0 && \$day != 0)
\$soob = \$soob . "  ";
if (\$day != 0)
\$soob = \$soob . \$day . " " . vypiska(\$day, 0) . ".";
``````