Good all the time of day.

Does anyone have an algorithm that considers how many days have passed from a certain date? And does anyone have any thoughts on how to write this? Are there any features like that? It only came to mind that days were divided by 365.25, months by 12, and the difference in years is multiplied by 365.25 ... but it turns out not exactly. I want something like:

<? /* YYYYmmdd - это высчитать и соединить легко, допустим 20110920 */ $today = $YYYYmmdd; /* $amoon - от какого дня считаем */ $moon = 19690721; /* дальше мы как то считаем это )) /* echo "Америкосы были на луне ".$raznica." дней назад."; ?> 

    2 answers 2

     $today = time(); $moon = mktime(0, 0, 0, 7, 21, 1969); echo "Америкосы были на луне ".floor(($today - $moon) / 86400)." дней назад."; 
    • Awesome! Brilliant! Ahrenet! Author hellish sotona! Thank! So everything is just ... - sergey

    Well, that's very rude. Although I, too, are rude enough and did not make a decision for dates that are less than 1970. (It was just too lazy.)

     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('jn-Y', $e); $dat = explode("-", $f); $day = $dat[0] - 1; $month = $dat[1] - 1; $year = $dat[2] - 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) . "."; 
    • mktime(0,0,0,date("m,d,Y")); o_O - Sh4dow
    • It was necessary to count precisely so that it turned out more precisely how many years, months and days had passed or remained until the date. - Grimon
    • Did you check the script, does it work? - ling
    • if it hadn't worked, then probably I wouldn’t bring it here. Here is an example of his work - line.simsru.com - Grimon